juanfont/headscale · error
getting container logs: %w
Error message
getting container logs: %w
What it means
Returned by `streamAndWait` when `cli.ContainerLogs` fails to attach to the container's output streams before waiting. With Follow:true the attach is a long-lived connection, so this fails on daemon connection issues or if the container vanished between create/start and attach. The function returns exitCode -1, so the real exit status is unknown.
Source
Thrown at cmd/hi/docker.go:329
hostConfig := &container.HostConfig{
AutoRemove: false, // We'll remove manually for better control
Binds: binds,
Mounts: mounts,
}
return cli.ContainerCreate(ctx, containerConfig, hostConfig, nil, nil, containerName)
}
// streamAndWait streams container output and waits for completion.
func streamAndWait(ctx context.Context, cli *client.Client, containerID string) (int, error) {
out, err := cli.ContainerLogs(ctx, containerID, container.LogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
})
if err != nil {
return -1, fmt.Errorf("getting container logs: %w", err)
}
defer out.Close()
go func() {
_, _ = io.Copy(os.Stdout, out)
}()
statusCh, errCh := cli.ContainerWait(ctx, containerID, container.WaitConditionNotRunning)
select {
case err := <-errCh:
if err != nil {
return -1, fmt.Errorf("waiting for container: %w", err)
}
case status := <-statusCh:
return int(status.StatusCode), nil
}
return -1, ErrUnexpectedContainerWaitView on GitHub (pinned to 565fd254d0)
Solutions
- Verify the container still exists: `docker ps -a | grep hs-`.
- Check daemon stability (`docker info`, journalctl for dockerd).
- Ensure no parallel cleanup job removes containers during the run.
- Retrying the run from scratch is safe — this is a pre-streaming failure.
Defensive patterns
Strategy: retry
Validate before calling
// confirm the container is still present just before streaming
if _, err := cli.ContainerInspect(ctx, containerID); err != nil {
return fmt.Errorf("container vanished before streaming: %w", err)
} Try / catch
if err := runDockerTest(ctx, config); err != nil {
if strings.Contains(err.Error(), "getting container logs") {
// attach-stage failure: verify daemon and container, re-run from scratch
}
} Prevention
- Don't force-remove test containers while their run is streaming.
- Ensure the docker socket/connection is stable for the whole run.
- Keep attach-friendly daemon versions (avoid daemon/client skew).
When it happens
Trigger: Daemon connection drops at attach time; the container was force-removed right after start; API version mismatch between client and daemon on the logs endpoint; context already cancelled/expired.
Common situations: Docker daemon restart or socket replacement mid-run; concurrent cleanup deleting the container; aggressive context timeouts wrapping `runDockerTest`.
Related errors
- executing test: %w
- ensuring image availability: %w
- creating container: %w
- starting container: %w
- waiting for container: %w
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/a6fde7866f1d98c9.
Report an issue: GitHub.