golang/go · error
failed to create server socket: %w
Error message
failed to create server socket: %w
What it means
After address parsing succeeds, `net.Listen("tcp", addr)` is called to open the viewer's TCP socket. If the kernel refuses the bind (port taken, privileged port without permission, no such interface, address in use), Listen returns an error that is wrapped and fatal. This is an environment/resource error, not a trace-format error.
Source
Thrown at src/cmd/trace/main.go:159
case "parsed":
logAndDie(debugProcessedEvents(tracef))
case "wire":
logAndDie(debugRawEvents(tracef))
case "footprint":
logAndDie(debugEventsFootprint(tracef))
default:
logAndDie(fmt.Errorf("invalid debug mode %s, want one of: parsed, wire, footprint", *debugFlag))
}
}
addr, err := listenAddr(*httpFlag)
if err != nil {
logAndDie(fmt.Errorf("malformed -http value %q: %v", *httpFlag, err))
}
ln, err := net.Listen("tcp", addr)
if err != nil {
logAndDie(fmt.Errorf("failed to create server socket: %w", err))
}
addr = ln.Addr().String()
url, simplified, err := addrURL(addr)
if err != nil {
logAndDie(fmt.Errorf("failed to compute server URL: %v", err))
}
log.Print("Preparing trace for viewer...")
parsed, err := parseTraceInteractive(tracef, traceSize)
if err != nil {
logAndDie(err)
}
// N.B. tracef not needed after this point.
// We might double-close, but that's fine; we ignore the error.
tracef.Close()
// Print a nice message for a partial trace.View on GitHub (pinned to b6b368adc5)
Solutions
- Free the port or pick a free one: `go tool trace -http=localhost:0 trace.out` lets the OS choose.
- If you need a specific port, find and kill the holder: `lsof -i :<port>` (Unix) then terminate it.
- For privileged ports, run with appropriate privileges or pick a port ≥1024.
- Check `ulimit -n` and raise the FD limit if you open many traces in a loop.
Example fix
// before $ go tool trace -http=:80 trace.out # as non-root // after $ go tool trace -http=:8080 trace.out
Defensive patterns
Strategy: retry
Validate before calling
// before binding, probe the port
ln, err := net.Listen("tcp", addr)
if err != nil { return err }
ln.Close() // go tool trace will re-open Prevention
- Prefer -http=localhost:0 to let the OS pick a free port.
- Kill prior viewer instances before starting a new one.
- Avoid privileged (<1024) ports unless running with appropriate privileges.
When it happens
Trigger: Another process already holds the requested port; binding <1024 as non-root; specifying an IP not present on any local interface; hitting a per-process file descriptor limit; SO_REUSEADDR unavailable on a TIME_WAIT socket.
Common situations: Re-running `go tool trace` while the previous viewer is still open in another terminal; hardcoded port 8080 colliding with a dev server; container restricted from binding the port; macOS/Windows firewall blocking the bind.
Related errors
- malformed -http value %q: %v
- failed to compute server URL: %v
- failed to start http server: %w
- 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/cf56cfd3ce956767.
Report an issue: GitHub.