benbjohnson/litestream · error
failed to read response: %w
Error message
failed to read response: %w
What it means
The connection to the daemon's control socket succeeded, but reading the HTTP response body failed via io.ReadAll. Since the body comes from the local Unix-socket HTTP server, this usually means the connection was cut mid-response — daemon crash, timeout cancellation, or a reset connection — rather than a client-side bug.
Source
Thrown at cmd/litestream/start.go:71
req := litestream.StartRequest{
Path: dbPath,
Timeout: *timeout,
}
reqBody, err := json.Marshal(req)
if err != nil {
return fmt.Errorf("failed to marshal request: %w", err)
}
resp, err := client.Post("http://localhost/start", "application/json", bytes.NewReader(reqBody))
if err != nil {
return fmt.Errorf("failed to connect to control socket: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response: %w", err)
}
if resp.StatusCode != http.StatusOK {
var errResp litestream.ErrorResponse
if err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != "" {
return fmt.Errorf("start failed: %s", errResp.Error)
}
return fmt.Errorf("start failed: %s", string(body))
}
var result litestream.StartResponse
if err := json.Unmarshal(body, &result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
confirmation := StartStopResult{
Status: result.Status,
DBPath: result.Path,View on GitHub (pinned to 4ed7a308f6)
Solutions
- Increase -timeout so the client doesn't abort mid-read of a slow /start response
- Check daemon logs for a crash or panic around the time of the request
- Retry the command; if the daemon is restarting, wait until it is healthy
- Ensure the daemon and CLI versions match so response framing is compatible
Defensive patterns
Strategy: retry
Validate before calling
// pre-check with a cheap request to the socket before the real one:
resp, err := client.Post("http://localhost/status", "application/json", nil)
_ = resp; _ = err // ensure daemon responds before long-running start Try / catch
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
// retry with a larger -timeout
} Prevention
- Set -timeout generously relative to how long starting replication can take
- Monitor daemon stability (no OOM/crash loops) before scripted starts
- Avoid killing/restarting the daemon while CLI commands are in flight
When it happens
Trigger: `litestream start` receives a connection but the daemon closes the connection before the full response is written; the client's -timeout http.Client timeout fires mid-read (context/deadline exceeded); the daemon panics while handling /start and the socket is torn down.
Common situations: Daemon restarts under load while the CLI request is in flight; -timeout too small so the client aborts while waiting for a slow start operation; kernel/oom-kills the daemon during the request.
Related errors
- failed to connect to control socket: %w
- failed to connect to control socket: %w
- failed to connect to control socket: %w
- failed to read response: %w
- failed to read response: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/1a91b9361d4fafb4.
Report an issue: GitHub.