Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove pools shutdown policy #88

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- errorlint # find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- copyloopvar # checks for pointers to enclosing loop variables
- gochecknoglobals # Checks that no globals are present in Go code
- gochecknoinits # Checks that no init functions are present in Go code
- gocognit # Computes and checks the cognitive complexity of functions
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
testpkg:
go test -v -race -cover -tags=debug ./...
test:
go test -v -race -cover -tags=race -tags=debug ./...
Comment on lines +1 to +2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge tags in the test command.

The go test command includes -tags=race and -tags=debug separately, which might not work as intended because the last -tags option will override the previous one. Merge them into a single -tags option to enable both features simultaneously.

Apply this diff to fix the command:

-	go test -v -race -cover -tags=race -tags=debug ./...
+	go test -v -race -cover -tags="race,debug" ./...
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test:
go test -v -race -cover -tags=race -tags=debug ./...
test:
go test -v -race -cover -tags="race,debug" ./...

29 changes: 1 addition & 28 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/roadrunner-server/errors"
"go.uber.org/zap"
Expand All @@ -29,8 +28,6 @@ type Plugin struct {

log *zap.Logger
factory pool.Factory

pools []Pool
}

// Init application provider.
Expand Down Expand Up @@ -84,8 +81,6 @@ func (p *Plugin) Init(cfg Configurer, log NamedLogger) error {

p.preparedEnvs = append(p.preparedEnvs, fmt.Sprintf("%s=%s", RrVersion, cfg.RRVersion()))

p.pools = make([]Pool, 0, 4)

p.factory, err = initFactory(p.log, p.cfg.Relay)
if err != nil {
return errors.E(op, err)
Expand Down Expand Up @@ -114,30 +109,10 @@ func (p *Plugin) Serve() chan error {
}

// Stop used to stop all allocated pools
func (p *Plugin) Stop(ctx context.Context) error {
func (p *Plugin) Stop(_ context.Context) error {
p.mu.Lock()
defer p.mu.Unlock()

wg := &sync.WaitGroup{}
wg.Add(len(p.pools))

// destroy all pools in parallel
for i := 0; i < len(p.pools); i++ {
go func(idx int) {
if p.pools[idx] == nil || p.pools[idx].(*staticPool.Pool) == nil {
wg.Done()
return
}
ctx2, cancel := context.WithTimeout(ctx, p.pools[idx].GetConfig().DestroyTimeout)
p.pools[idx].Destroy(ctx2)
cancel()
wg.Done()
}(i)
}

wg.Wait()
// just to be sure that all logs are synced
time.Sleep(time.Second)
return p.factory.Close()
}

Expand Down Expand Up @@ -165,8 +140,6 @@ func (p *Plugin) NewPool(ctx context.Context, cfg *pool.Config, env map[string]s
return nil, err
}

p.pools = append(p.pools, pl)

return pl, nil
}

Expand Down
Loading