Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

fix: panic if there are no workers #128

Merged
merged 7 commits into from
Jun 26, 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 .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Run linter
uses: golangci/[email protected] # Action page: <https://github.com/golangci/golangci-lint-action>
with:
version: v1.57 # without patch version
version: v1.59 # without patch version
only-new-issues: false # show only new issues if it's a pull request
args: --timeout=10m --build-tags=race
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.2"]
php: ["8.3"]
go: [stable]
os: ["ubuntu-latest"]
steps:
Expand Down
3 changes: 2 additions & 1 deletion pool/static_pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ func Test_StaticPool_RemoveWorker(t *testing.T) {
_, err = p.Exec(ctx, &payload.Payload{Body: []byte("hello"), Context: nil}, make(chan struct{}))
assert.NoError(t, err)

assert.Len(t, p.Workers(), 1)
// after removing all workers, we should have 1 worker + 1 we added
assert.Len(t, p.Workers(), 2)

p.Destroy(ctx)
}
Expand Down
4 changes: 2 additions & 2 deletions pool/static_pool/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func Test_SupervisedPool_RemoveNoWorkers(t *testing.T) {
assert.NoError(t, p.RemoveWorker(ctx))
}

assert.Len(t, p.Workers(), 0)
assert.Len(t, p.Workers(), 1)
p.Destroy(ctx)
}

Expand Down Expand Up @@ -208,7 +208,7 @@ func Test_SupervisedPool_RemoveWorker(t *testing.T) {
_, err = p.Exec(ctx, &payload.Payload{Body: []byte("hello"), Context: nil}, make(chan struct{}))
assert.NoError(t, err)

assert.Len(t, p.Workers(), 1)
assert.Len(t, p.Workers(), 2)

p.Destroy(ctx)
}
Expand Down
10 changes: 10 additions & 0 deletions worker_watcher/worker_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (ww *WorkerWatcher) RemoveWorker(ctx context.Context) error {
return err
}

// can't remove the last worker
if atomic.LoadUint64(&ww.numWorkers) == 1 {
ww.log.Warn("can't remove the last worker", zap.Int64("pid", w.Pid()))
return nil
}

// destroy and stop
w.State().Transition(fsm.StateDestroyed)
_ = w.Stop()
Expand Down Expand Up @@ -403,6 +409,10 @@ func (ww *WorkerWatcher) wait(w *worker.Process) {
err = ww.Allocate()
if err != nil {
ww.log.Error("failed to allocate the worker", zap.String("internal_event_name", events.EventWorkerError.String()), zap.Error(err))
if atomic.LoadUint64(&ww.numWorkers) == 0 {
panic("no workers available, can't run the application")
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved

return
}

Expand Down
Loading