juanfont/headscale · error
waiting for container: %w
Error message
waiting for container: %w
What it means
Returned by `streamAndWait` when the `cli.ContainerWait` error channel yields an error — the container stopped in a way that produced no clean status, or the wait call itself failed (context cancelled, daemon error). Distinct from `ErrUnexpectedContainerWait`, which fires only when the select falls through with neither channel delivering.
Source
Thrown at cmd/hi/docker.go:341
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, ErrUnexpectedContainerWait
}
// waitForContainerFinalization ensures all test containers have properly finished and flushed their output.
func waitForContainerFinalization(ctx context.Context, cli *client.Client, testContainerID string, verbose bool) error {
// First, get all related test containers
containers, err := cli.ContainerList(ctx, container.ListOptions{All: true})
if err != nil {
return fmt.Errorf("listing containers: %w", err)
}
testContainers := getCurrentTestContainers(containers, testContainerID, verbose)
View on GitHub (pinned to 565fd254d0)
Solutions
- If interrupted intentionally, clean up with `go run ./cmd/hi clean` before the next run.
- Raise the CI/job timeout if the suite legitimately needs longer.
- Verify no concurrent prune/cleanup runs during tests.
- Re-run; artifacts under control_logs/ survive for diagnosis.
Defensive patterns
Strategy: retry
Try / catch
if err := runDockerTest(ctx, config); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
// caller cancelled: run `go run ./cmd/hi clean` before the next attempt
} else if strings.Contains(err.Error(), "waiting for container") {
// daemon-side wait failure: check daemon health, then retry
}
} Prevention
- Size outer context timeouts to config.Timeout plus overhead.
- Prevent concurrent cleanup/prune jobs from removing containers mid-wait.
- Handle SIGINT by cleaning up (hi clean) before restarting.
When it happens
Trigger: Context passed to runDockerTest is cancelled (Ctrl-C propagating, parent timeout); daemon error while waiting (container forcibly removed with `docker rm -f`); wait API interrupted by daemon restart.
Common situations: User interrupts the run; CI job timeout cancels the command; another terminal runs `hi cleanup` or `docker prune` mid-test.
Related errors
- executing test: %w
- ensuring image availability: %w
- creating container: %w
- starting container: %w
- getting container logs: %w
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/0a399d4eec5d5800.
Report an issue: GitHub.