From f4ca750ebc87713b97ba2c7697d31d726b3a71a9 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 13:42:13 +0200 Subject: [PATCH 1/6] fix: panic if there are no workers Signed-off-by: Valery Piashchynski --- worker_watcher/worker_watcher.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/worker_watcher/worker_watcher.go b/worker_watcher/worker_watcher.go index 1a54885..482ecd9 100644 --- a/worker_watcher/worker_watcher.go +++ b/worker_watcher/worker_watcher.go @@ -403,6 +403,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") + } + return } From 82e59c0555e093597d7b9326ca5645dac1d6456c Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 14:02:04 +0200 Subject: [PATCH 2/6] chore: do not delete the last worker Signed-off-by: Valery Piashchynski --- worker_watcher/worker_watcher.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/worker_watcher/worker_watcher.go b/worker_watcher/worker_watcher.go index 482ecd9..ce0f866 100644 --- a/worker_watcher/worker_watcher.go +++ b/worker_watcher/worker_watcher.go @@ -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() From 13a8367d2ac35d9aeccac087f55e6c02ec873915 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 14:15:02 +0200 Subject: [PATCH 3/6] chore: update CI Signed-off-by: Valery Piashchynski --- .github/workflows/linters.yml | 2 +- .github/workflows/linux.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 6702833..72d5d4d 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -18,6 +18,6 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v6.0.1 # Action page: 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 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7dcf927..860c016 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.2"] + php: ["8.3"] go: [stable] os: ["ubuntu-latest"] steps: From 8ec5f75bd44380c3942a4d3e8549edb5b74b34fe Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 14:26:34 +0200 Subject: [PATCH 4/6] chore: fix test with removing workers Signed-off-by: Valery Piashchynski --- pool/static_pool/pool_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pool/static_pool/pool_test.go b/pool/static_pool/pool_test.go index 7ade03c..4f9735b 100644 --- a/pool/static_pool/pool_test.go +++ b/pool/static_pool/pool_test.go @@ -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) } From 41e4745b6c18e5885ecdfc19d17b7e5b124a1688 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 14:36:58 +0200 Subject: [PATCH 5/6] fix: supervisor_test with remove workers Signed-off-by: Valery Piashchynski --- pool/static_pool/supervisor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/static_pool/supervisor_test.go b/pool/static_pool/supervisor_test.go index be74819..6115f46 100644 --- a/pool/static_pool/supervisor_test.go +++ b/pool/static_pool/supervisor_test.go @@ -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) } From 432b1d765bdd49ff0cd491ec5dcb17d0cbaf7d5a Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Tue, 25 Jun 2024 15:09:56 +0200 Subject: [PATCH 6/6] fix: remove worker test Signed-off-by: Valery Piashchynski --- pool/static_pool/supervisor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pool/static_pool/supervisor_test.go b/pool/static_pool/supervisor_test.go index 6115f46..a2d8709 100644 --- a/pool/static_pool/supervisor_test.go +++ b/pool/static_pool/supervisor_test.go @@ -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) }