Skip to content

Commit

Permalink
chore: remove central pools shutdown policy
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Aug 30, 2024
1 parent 3cdc644 commit 08e1f1b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
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 ./...
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

0 comments on commit 08e1f1b

Please sign in to comment.