{"record":{"id":"ac41d06304be4d18","repo":"benbjohnson/litestream","slug":"failed-to-read-response-w-ac41d0","errorCode":null,"errorMessage":"failed to read response: %w","messagePattern":"failed to read response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/register.go","lineNumber":80,"sourceCode":"\n\treq := litestream.RegisterDatabaseRequest{\n\t\tPath:       dbPath,\n\t\tReplicaURL: replicaURL,\n\t}\n\treqBody, err := json.Marshal(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}\n\n\tresp, err := client.Post(\"http://localhost/register\", \"application/json\", bytes.NewReader(reqBody))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to connect to control socket: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tvar errResp litestream.ErrorResponse\n\t\tif err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != \"\" {\n\t\t\treturn fmt.Errorf(\"register failed: %s\", errResp.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"register failed: %s\", string(body))\n\t}\n\n\tvar result litestream.RegisterDatabaseResponse\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse response: %w\", err)\n\t}\n\n\tconfirmation := RegisterResult{\n\t\tStatus:  result.Status,\n\t\tDBPath:  result.Path,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/register.go#L62-L98","documentation":"After a successful POST to the control socket, the command reads the entire response body with io.ReadAll. If reading fails (connection reset mid-response, socket error, or the client -timeout firing while streaming the body), the error is wrapped as 'failed to read response'.","triggerScenarios":"The daemon closes the connection before the full response is delivered; the -timeout expires while io.ReadAll is still draining the body; I/O error on the Unix socket.","commonSituations":"Very small -timeout values with a slow/blocked daemon handler; daemon killed mid-request (systemd restart, OOM kill); flaky socket conditions under heavy load.","solutions":["Increase -timeout (e.g. -timeout 60 or higher)","Retry the register command — registration is idempotent (returns already_registered)","Check daemon logs around the time of the failure for crashes or handler panics","Verify system resources (OOM killer, disk) if the daemon dies mid-response"],"exampleFix":"// before\nlitestream register -timeout 1 -replica s3://b/p /db\n// after\nlitestream register -timeout 60 -replica s3://b/p /db","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := registerCmd.Run(ctx, args); err != nil {\n    if strings.Contains(err.Error(), \"failed to read response\") {\n        time.Sleep(backoff)\n        err = registerCmd.Run(ctx, args) // registration is idempotent\n    }\n}","preventionTips":["Use a sane -timeout (>= 30s) so body reads aren't cut off","Ensure the daemon isn't being restarted/killed mid-request (check systemd/OOM logs)","Retry register — it is idempotent (already_registered)"],"tags":["network","io","unix-socket"],"backgroundTag":"network-request-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}