feat: dynamic sidecar port with EADDRINUSE fallback#375
Open
Conversation
Rust probes port 46123 via TcpListener::bind; if busy, binds port 0 for an OS-assigned ephemeral port. The actual port is stored in LocalApiState, passed to sidecar via LOCAL_API_PORT env, and exposed to frontend via get_local_api_port IPC command. Frontend resolves the port lazily on first API call (with retry-on-failure semantics) and caches it. All hardcoded 46123 references replaced with dynamic getApiBaseUrl()/getLocalApiPort() accessors. CSP connect-src broadened to http://127.0.0.1:* (frame-src unchanged).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TcpListener::bind; if busy, binds port 0 for OS-assigned ephemeral portLocalApiState, passed to sidecar viaLOCAL_API_PORTenv, exposed to frontend viaget_local_api_portIPC command46123references replaced with dynamicgetApiBaseUrl()/getLocalApiPort()accessorsconnect-srcbroadened tohttp://127.0.0.1:*(frame-srcunchanged)Motivation
When port 46123 is occupied (stale sidecar from previous crash, another app, or dev restart), the sidecar crashes silently with
exit(1)and ALL panels show UNAVAILABLE. This particularly affects Windows where Node.js processes may linger after app close.Files changed
src-tauri/src/main.rsLocalApiState.port,get_local_api_portIPC,DesktopRuntimeInfo.local_api_portsrc/services/runtime.tsresolveLocalApiPort(),getLocalApiPort(), dynamicgetApiBaseUrl(), per-call URL in fetch patchsrc/services/runtime-config.tsgetApiBaseUrl()instead of hardcoded constantssrc/settings-main.tsresolveLocalApiPort()at init,getSidecarBase()dynamicsrc/components/LiveNewsPanel.tsgetApiBaseUrl()src/components/ServiceStatusPanel.tsgetLocalApiPort()index.html+tauri.conf.jsonconnect-src→http://127.0.0.1:*Test plan
cargo checkpassesnpx tsc --noEmitpassesnode -e "require('net').createServer().listen(46123, '127.0.0.1')", launch app → sidecar binds alternate port → panels loaddesktop.logforlocal API sidecar using port <N>