[Low] xe node prints "API/UI listening" even when the bind fails; node keeps running headless
Report
Summary
xe node prints "API listening on port N" / "UI listening on port N" even when the bind fails, and the node keeps running headless with no API. The "listening" lines are printed before ListenAndServe attempts the bind, so a bind failure only surfaces as a log ERROR inside the goroutine while stdout claims success.
Root Cause
- The "listening" log lines are printed inside the server goroutines before
ListenAndServeis called (cmd/xe/main.go:1466-1468API,:1541UI). - The stdout lines (
:1550"API listening on port %d",:1553"UI listening on port %d") print unconditionally after launching the goroutines. - A bind failure only surfaces as a log ERROR inside the goroutine; nothing fails the startup, so the node keeps running with no API.
Verification
Executed PoC (squatted 127.0.0.1:18080 with a dummy server, then ran xe node --api-port 18080 --ui --ui-port 18081):
INFO "API listening on 127.0.0.1:18080"
ERROR "API server error: listen tcp 127.0.0.1:18080: bind: address already in use"
API listening on port 18080
UI listening on port 18081
The process kept running until killed. Bonus consequence: the UI claims to proxy /api/* to the dead API port — whatever process holds that port receives the wallet UI's API traffic (UI listening on 127.0.0.1:18081 (proxying /api/* to http://127.0.0.1:18080, wallet enabled)).
Note on related reports
Searched "API listening port bind fail" and "address already in use bind" — #558 (failed node.New() leaks listener/goroutines) and #60 (SIGTERM shutdown hang) are adjacent but different mechanisms.
Suggested fix
Bind the listeners (or attempt ListenAndServe and check the error) before printing the "listening" lines, and fail startup — or at least exit non-zero — when a configured server cannot bind.
Thread
Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-16976 and says what differs; it is read like any other.