golang/go · error
failed to start http server: %w
Error message
failed to start http server: %w
What it means
`http.Serve(ln, mux)` blocks while serving the trace viewer; if it returns a non-nil error the tool prints it and exits 1 via `logAndDie`. Because the error is wrapped unconditionally (including the nil case being impossible to reach in practice — Serve only returns nil on `ErrServerClosed`-style shutdowns via Server), any serve-time failure is fatal. Typical causes are the listener closing underneath the server or a handshake/protocol error on accept.
Source
Thrown at src/cmd/trace/main.go:250
mux.HandleFunc("/syscall", traceviewer.SVGProfileHandlerFunc(pprofByGoroutine(computePprofSyscall(), parsed)))
mux.HandleFunc("/sched", traceviewer.SVGProfileHandlerFunc(pprofByGoroutine(computePprofSched(), parsed)))
// Region-based pprof endpoints.
mux.HandleFunc("/regionio", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofIO(), parsed)))
mux.HandleFunc("/regionblock", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofBlock(), parsed)))
mux.HandleFunc("/regionsyscall", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSyscall(), parsed)))
mux.HandleFunc("/regionsched", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSched(), parsed)))
// Region endpoints.
mux.HandleFunc("/userregions", UserRegionsHandlerFunc(parsed))
mux.HandleFunc("/userregion", UserRegionHandlerFunc(parsed))
// Task endpoints.
mux.HandleFunc("/usertasks", UserTasksHandlerFunc(parsed))
mux.HandleFunc("/usertask", UserTaskHandlerFunc(parsed))
err = http.Serve(ln, mux)
logAndDie(fmt.Errorf("failed to start http server: %w", err))
}
func logAndDie(err error) {
if err == nil {
os.Exit(0)
}
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
// listenAddr returns the address to listen on given the addr address flag.
//
// If addr does not specify a host (e.g., ":8080"), then default to listening
// only on localhost rather than all addresses. To listen on all addresses,
// explicitly set the unspecified address (e.g., "0.0.0.0:8080").
func listenAddr(addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {View on GitHub (pinned to b6b368adc5)
Solutions
- Re-run the command — most serve failures are transient listener-state issues.
- Reduce concurrent browser tabs/requests hitting the viewer to lower FD pressure.
- Check `dmesg`/system logs for OOM or socket-reaping evidence if it recurs.
- Save the trace file and serve it from a more stable host if the container is the problem.
Defensive patterns
Strategy: try-catch
Try / catch
// if embedding the viewer, prefer http.Server with Shutdown
srv := &http.Server{Handler: mux}
if err := srv.Serve(ln); err != nil && err != http.ErrServerClosed {
log.Fatal(err)
} Prevention
- Run the viewer in a stable environment with adequate file descriptors.
- Limit concurrent browser tabs refreshing heavy profiles.
When it happens
Trigger: Another process kills/closes the listener FD; the process receives signals that close the socket; `http.Serve` hits repeated Accept errors (EMFILE, too many open files); abrupt listener removal on container shutdown.
Common situations: Long-running viewer killed by OOM killer or container runtime; hitting FD exhaustion from many concurrent browser tabs refreshing profiles; running inside an environment that reaps sockets aggressively.
Related errors
- malformed -http value %q: %v
- failed to create server socket: %w
- failed to compute server URL: %v
- globalThis.crypto is not available, polyfill required (crypt
- globalThis.performance is not available, polyfill required (
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/1fbad62ec9ddf039.
Report an issue: GitHub.