{"record":{"id":"1fbad62ec9ddf039","repo":"golang/go","slug":"failed-to-start-http-server-w","errorCode":null,"errorMessage":"failed to start http server: %w","messagePattern":"failed to start http server: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/main.go","lineNumber":250,"sourceCode":"\tmux.HandleFunc(\"/syscall\", traceviewer.SVGProfileHandlerFunc(pprofByGoroutine(computePprofSyscall(), parsed)))\n\tmux.HandleFunc(\"/sched\", traceviewer.SVGProfileHandlerFunc(pprofByGoroutine(computePprofSched(), parsed)))\n\n\t// Region-based pprof endpoints.\n\tmux.HandleFunc(\"/regionio\", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofIO(), parsed)))\n\tmux.HandleFunc(\"/regionblock\", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofBlock(), parsed)))\n\tmux.HandleFunc(\"/regionsyscall\", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSyscall(), parsed)))\n\tmux.HandleFunc(\"/regionsched\", traceviewer.SVGProfileHandlerFunc(pprofByRegion(computePprofSched(), parsed)))\n\n\t// Region endpoints.\n\tmux.HandleFunc(\"/userregions\", UserRegionsHandlerFunc(parsed))\n\tmux.HandleFunc(\"/userregion\", UserRegionHandlerFunc(parsed))\n\n\t// Task endpoints.\n\tmux.HandleFunc(\"/usertasks\", UserTasksHandlerFunc(parsed))\n\tmux.HandleFunc(\"/usertask\", UserTaskHandlerFunc(parsed))\n\n\terr = http.Serve(ln, mux)\n\tlogAndDie(fmt.Errorf(\"failed to start http server: %w\", err))\n}\n\nfunc logAndDie(err error) {\n\tif err == nil {\n\t\tos.Exit(0)\n\t}\n\tfmt.Fprintf(os.Stderr, \"%s\\n\", err)\n\tos.Exit(1)\n}\n\n// listenAddr returns the address to listen on given the addr address flag.\n//\n// If addr does not specify a host (e.g., \":8080\"), then default to listening\n// only on localhost rather than all addresses. To listen on all addresses,\n// explicitly set the unspecified address (e.g., \"0.0.0.0:8080\").\nfunc listenAddr(addr string) (string, error) {\n\thost, port, err := net.SplitHostPort(addr)\n\tif err != nil {","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/main.go#L232-L268","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// if embedding the viewer, prefer http.Server with Shutdown\nsrv := &http.Server{Handler: mux}\nif err := srv.Serve(ln); err != nil && err != http.ErrServerClosed {\n    log.Fatal(err)\n}","preventionTips":["Run the viewer in a stable environment with adequate file descriptors.","Limit concurrent browser tabs refreshing heavy profiles."],"tags":["network","go-tool-trace","http-server","runtime"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}