{"record":{"id":"69e4bef9f8baf090","repo":"hyperledger/fabric","slug":"error-waiting-for-container-to-complete-s","errorCode":null,"errorMessage":"Error waiting for container to complete: %s","messagePattern":"Error waiting for container to complete: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/utils.go","lineNumber":150,"sourceCode":"\t// Launch the actual build, realizing the Env/Cmd specified at container creation\n\t// -----------------------------------------------------------------------------------\n\t_, err = client.ContainerStart(context.Background(), container.ID, dcli.ContainerStartOptions{})\n\tif err != nil {\n\t\tbuff, _ := io.ReadAll(cw.Reader)\n\t\tcw.Close()\n\t\treturn fmt.Errorf(\"Error executing build: %s \\\"%s\\\"\", err, string(buff))\n\t}\n\n\t// -----------------------------------------------------------------------------------\n\t// Wait for the build to complete and gather the return value\n\t// -----------------------------------------------------------------------------------\n\tresWait := client.ContainerWait(context.Background(), container.ID, dcli.ContainerWaitOptions{})\n\tvar res dcontainer.WaitResponse\n\tselect {\n\tcase res = <-resWait.Result:\n\tcase err = <-resWait.Error:\n\t\tcw.Close()\n\t\treturn fmt.Errorf(\"Error waiting for container to complete: %s\", err)\n\t}\n\n\t// Wait for stream copying to complete before accessing stdout.\n\tdefer cw.Close()\n\tbuff, _ := io.ReadAll(cw.Reader)\n\tif res.StatusCode > 0 {\n\t\tlogger.Errorf(\"Docker build failed using options: %s\", opts)\n\t\treturn fmt.Errorf(\"Error returned from build: %d \\\"%s\\\"\", res.StatusCode, string(buff))\n\t}\n\n\tlogger.Debugf(\"Build output is %s\", string(buff))\n\n\t// -----------------------------------------------------------------------------------\n\t// Finally, download the result\n\t// -----------------------------------------------------------------------------------\n\tresCont, err := client.CopyFromContainer(context.Background(), container.ID, dcli.CopyFromContainerOptions{SourcePath: \"/chaincode/output/.\"})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error downloading output: %s\", err)","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/utils.go#L132-L168","documentation":"After ContainerStart succeeds, DockerBuild blocks on client.ContainerWait. If the wait call's error channel delivers an error (docker API/stream failure while waiting for the container to exit) instead of a WaitResponse, the attached container stream is closed and this error is returned. It means the build outcome is unknown because the daemon-side wait itself failed, not that compilation failed.","triggerScenarios":"The ContainerWait result channel's Error channel receives a value: the docker daemon connection dropped while waiting, the container was forcibly removed by another process during the wait, or the daemon returned an API error on the wait endpoint.","commonSituations":"Docker daemon restart or crash during a long chaincode compilation; an external 'docker rm -f' (e.g. a cleanup script or timeout killer) removing the ephemeral builder container mid-build; network interruption between the peer and a remote docker endpoint (DOCKER_HOST) during the wait.","solutions":["Check docker daemon logs and uptime (docker info, journalctl -u docker) for a restart or crash during the build window","Ensure nothing else removes containers concurrently (cleanup scripts, orchestrators, docker system prune with --force)","Retry the chaincode build; transient daemon/connection failures usually succeed on a second attempt","If using a remote DOCKER_HOST, verify the connection is stable and increase daemon/API timeouts"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check daemon connectivity before starting a build\nif _, err := client.Ping(context.Background()); err != nil {\n    return fmt.Errorf(\"docker daemon unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"const maxAttempts = 3\nfor i := 1; i <= maxAttempts; i++ {\n    err := util.DockerBuild(opts, client)\n    if err == nil { break }\n    if strings.Contains(err.Error(), \"Error waiting for container to complete\") && i < maxAttempts {\n        time.Sleep(time.Duration(i) * time.Second)\n        continue\n    }\n    return err\n}","preventionTips":["Never run docker rm -f / prune scripts that could touch peer-managed builder containers","Ensure the docker daemon is stable (watch for restarts during long builds)","Use a local docker socket rather than an unreliable remote DOCKER_HOST","Bound build durations so containers are not left waiting indefinitely"],"tags":["docker","container-wait","daemon","chaincode-build"],"backgroundTag":"docker-daemon-connection-lost","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}