Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(docker): clamp non-positive worker count in the stat fan-out
Sergey Kozyrenko8212802c8498
diff --git a/backend/pkg/docker/client.go b/backend/pkg/docker/client.goindex 3c1739c1..aae4a7f2 100644--- a/backend/pkg/docker/client.go+++ b/backend/pkg/docker/client.go@@ -646,6 +646,13 @@ func statContainerEntries(workers int,statFn func(context.Context, string) (container.PathStat, error),) ([]container.PathStat, error) {+ // errgroup.SetLimit(0) blocks the first Go() forever and SetLimit(<0) runs+ // unbounded; clamp a non-positive count to the standard bound so the pool+ // never deadlocks or floods the Docker daemon.+ if workers <= 0 {+ workers = containerListWorkers+ }+stats := make([]container.PathStat, len(names))errs := make([]error, len(names))diff --git a/backend/pkg/docker/client_statfanout_test.go b/backend/pkg/docker/client_statfanout_test.goindex 4976853f..ed9e2609 100644--- a/backend/pkg/docker/client_statfanout_test.go+++ b/backend/pkg/docker/client_statfanout_test.go@@ -102,6 +102,39 @@ func TestStatContainerEntries_RespectsConcurrencyLimit(t *testing.T) {}}+// A non-positive worker count must fall back to a safe bound rather than+// deadlock (errgroup SetLimit(0)) or run unbounded (SetLimit(<0)).+func TestStatContainerEntries_NonPositiveWorkersFallBack(t *testing.T) {+ names := make([]string, 50)+ for i := range names {+ names[i] = fmt.Sprintf("e%d", i)+ }+ for _, workers := range []int{0, -1} {+ t.Run(fmt.Sprintf("workers=%d", workers), func(t *testing.T) {+ type out struct {+ stats []container.PathStat+ err error+ }+ done := make(chan out, 1)+ go func() {+ stats, err := statContainerEntries(context.Background(), names, workers, okStat)+ done <- out{stats, err}+ }()+ select {+ case got := <-done:+ if got.err != nil {+ t.Fatalf("unexpected error: %v", got.err)+ }+ if len(got.stats) != len(names) {+ t.Fatalf("got %d stats, want %d", len(got.stats), len(names))+ }+ case <-time.After(3 * time.Second):+ t.Fatal("statContainerEntries hung with a non-positive worker count")+ }+ })+ }+}+// The caller's context reaches each stat call, so a cancellation aborts them.func TestStatContainerEntries_ContextPropagates(t *testing.T) {ctx, cancel := context.WithCancel(context.Background())