pub async fn spawn_sidecar(
index: SharedIndex,
bind_host: &str,
repo_root: Option<PathBuf>,
control_state_dir: Option<ControlStateDir>,
) -> Result<SidecarHandle>Expand description
Spawn the HTTP sidecar.
- Reads
SYMFORGE_SIDECAR_BINDenv var (default"127.0.0.1"). - Calls
port_file::check_stale(bind_host)to clean up any stale files. - Creates a
socket2::Socket, setsSO_REUSEADDR, binds to{bind_host}:0(OS assigns the port), then listens with backlog 1024.SO_REUSEADDRlets the bind succeed when the chosen ephemeral port is still in TIME_WAIT from a recently-closed listener; this keeps rapid daemon restarts and parallel test fan-out from racing on Windows. - Hands the socket to
tokio::net::TcpListener::from_std. - Writes port and PID files via
port_file. - Creates
SidecarStatewithTokenStatsand empty symbol cache. - Builds the axum router via
router::build_router. - Spawns
axum::servewith graceful shutdown wired to a oneshot channel. - After the server completes, calls
port_file::cleanup_files(). - Returns
SidecarHandle { port, shutdown_tx, server_join, token_stats }.