golang/go · error
failed to compute server URL: %v
Error message
failed to compute server URL: %v
What it means
Once the listener is up, `addrURL(addr)` converts the bound address into an `http://...` URL by calling `net.SplitHostPort` again on the listener's resolved address. If the resolved `ln.Addr().String()` cannot be split into host:port (extremely unlikely for a TCP listener), the URL computation fails and the tool aborts before serving. This is a defensive guard around an expected-invariant case.
Source
Thrown at src/cmd/trace/main.go:165
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.
if parsed.err != nil {
log.Printf("Encountered error, but able to proceed. Error: %v", parsed.err)
lost := parsed.size - parsed.valid
pct := float64(lost) / float64(parsed.size) * 100
log.Printf("Lost %.2f%% of the latest trace data due to error (%s of %s)", pct, byteCount(lost), byteCount(parsed.size))View on GitHub (pinned to b6b368adc5)
Solutions
- Retry with a plain `-http=localhost:<port>` to ensure a normal TCP listener address.
- Update/repair the Go toolchain — a malformed listener address indicates a toolchain or platform bug.
- If running a patched tool, ensure the listener's Addr() returns a valid host:port string.
Defensive patterns
Strategy: try-catch
Try / catch
if _, _, err := net.SplitHostPort(ln.Addr().String()); err != nil {
log.Printf("listener returned unexpected address format: %v", err)
} Prevention
- Use a stock net.Listener; do not wrap it with custom Addr() implementations.
- Keep your Go toolchain current.
When it happens
Trigger: Effectively only if `net.Listener.Addr().String()` returns a malformed string, which does not happen for standard TCP listeners. Could occur with a custom/intercepted net.Listener in a fork, or on platforms whose net package returns nonstandard address formatting.
Common situations: Rare in stock Go; seen when a third-party wrapper proxies the listener (e.g., a custom dialer/library that fakes listener addresses), or in stripped/odd toolchain builds.
Related errors
- malformed -http value %q: %v
- failed to create server socket: %w
- failed to start http server: %w
- stopped after 10 redirects
- file URL specifies non-local host
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/33d9eb8fc8151e33.
Report an issue: GitHub.