{"record":{"id":"a5e643d8f01c998d","repo":"vxcontrol/pentagi","slug":"failed-to-get-all-containers-w","errorCode":null,"errorMessage":"failed to get all containers: %w","messagePattern":"failed to get all containers: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/docker/client.go","lineNumber":796,"sourceCode":"\t}\n\n\tlogger.Info(\"container removed\")\n\n\treturn nil\n}\n\nfunc (dc *dockerClient) Cleanup(ctx context.Context) error {\n\tlogger := dc.logger.WithContext(ctx).WithField(\"docker\", \"cleanup\")\n\tlogger.Info(\"cleaning up containers and making all flows finished...\")\n\n\tflows, err := dc.db.GetFlows(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get all flows: %w\", err)\n\t}\n\n\tcontainers, err := dc.db.GetContainers(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get all containers: %w\", err)\n\t}\n\n\tflowsStatusMap := make(map[int64]database.FlowStatus)\n\tfor _, flow := range flows {\n\t\tflowsStatusMap[flow.ID] = flow.Status\n\t}\n\tflowContainersMap := make(map[int64][]database.Container)\n\tfor _, container := range containers {\n\t\tflowContainersMap[container.FlowID] = append(flowContainersMap[container.FlowID], container)\n\t}\n\n\tvar wg sync.WaitGroup\n\tremoveContainer := func(containerID string, dbID int64) {\n\t\tdefer wg.Done()\n\t\tlogger := logger.WithField(\"local_id\", containerID)\n\n\t\tif err := dc.RemoveContainer(ctx, containerID, dbID); err != nil {\n\t\t\tlogger.WithError(err).Errorf(\"failed to remove container\")","sourceCodeStart":778,"sourceCodeEnd":814,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/docker/client.go#L778-L814","documentation":"After successfully fetching flows, Cleanup fetches all container rows via GetContainers to build the status map; a failure here is wrapped with this message. Cleanup aborts before touching any container.","triggerScenarios":"dc.db.GetContainers fails during Cleanup: DB connection lost between the two queries, lock/timeout on the containers table, or schema mismatch.","commonSituations":"Flaky DB connection dropping mid-Cleanup; long-running transaction locking containers; migration drift leaving the containers table inconsistent; pool exhaustion under heavy teardown load.","solutions":["Confirm DB health and re-run Cleanup once connectivity is restored","Check locks on the containers table and resolve blocking transactions","Verify goose migrations are up to date for the containers schema","Wrap the fetch sequence in a retry with backoff since both reads are idempotent"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := dc.Cleanup(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to get all containers\") {\n        time.Sleep(retryDelay)\n        return dc.Cleanup(ctx)\n    }\n    return err\n}","preventionTips":["Fetch flows and containers with a consistent snapshot (single transaction) if staleness matters","Keep connection-pool limits above concurrent cleanup load","Apply migrations before Cleanup runs","Alert on lock waits on the containers table"],"tags":["database","postgresql","startup-cleanup"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}