{"record":{"id":"cf56cfd3ce956767","repo":"golang/go","slug":"failed-to-create-server-socket-w","errorCode":null,"errorMessage":"failed to create server socket: %w","messagePattern":"failed to create server socket: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/main.go","lineNumber":159,"sourceCode":"\t\tcase \"parsed\":\n\t\t\tlogAndDie(debugProcessedEvents(tracef))\n\t\tcase \"wire\":\n\t\t\tlogAndDie(debugRawEvents(tracef))\n\t\tcase \"footprint\":\n\t\t\tlogAndDie(debugEventsFootprint(tracef))\n\t\tdefault:\n\t\t\tlogAndDie(fmt.Errorf(\"invalid debug mode %s, want one of: parsed, wire, footprint\", *debugFlag))\n\t\t}\n\t}\n\n\taddr, err := listenAddr(*httpFlag)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"malformed -http value %q: %v\", *httpFlag, err))\n\t}\n\n\tln, err := net.Listen(\"tcp\", addr)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to create server socket: %w\", err))\n\t}\n\n\taddr = ln.Addr().String()\n\turl, simplified, err := addrURL(addr)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to compute server URL: %v\", err))\n\t}\n\n\tlog.Print(\"Preparing trace for viewer...\")\n\tparsed, err := parseTraceInteractive(tracef, traceSize)\n\tif err != nil {\n\t\tlogAndDie(err)\n\t}\n\t// N.B. tracef not needed after this point.\n\t// We might double-close, but that's fine; we ignore the error.\n\ttracef.Close()\n\n\t// Print a nice message for a partial trace.","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/main.go#L141-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ go tool trace -http=:80 trace.out  # as non-root\n// after\n$ go tool trace -http=:8080 trace.out","handlingStrategy":"retry","validationCode":"// before binding, probe the port\nln, err := net.Listen(\"tcp\", addr)\nif err != nil { return err }\nln.Close() // go tool trace will re-open","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["network","go-tool-trace","environment","bind-failure"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}