{"record":{"id":"9e49336864fa5557","repo":"LGUG2Z/komorebi","slug":"could-not-start-tcp-server","errorCode":null,"errorMessage":"could not start tcp server","messagePattern":"could not start tcp server","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"komorebi/src/process_command.rs","lineNumber":149,"sourceCode":"                        }\n                        Err(error) => {\n                            tracing::error!(\"{}\", error);\n                            break;\n                        }\n                    }\n                }\n            })\n            .join();\n\n            tracing::error!(\"restarting failed thread\");\n        }\n    });\n}\n\n#[tracing::instrument]\npub fn listen_for_commands_tcp(wm: Arc<Mutex<WindowManager>>, port: usize) {\n    let listener =\n        TcpListener::bind(format!(\"0.0.0.0:{port}\")).expect(\"could not start tcp server\");\n\n    std::thread::spawn(move || {\n        tracing::info!(\"listening on 0.0.0.0:43663\");\n        for client in listener.incoming() {\n            match client {\n                Ok(mut stream) => {\n                    net2::TcpStreamExt::set_keepalive(&stream, Some(Duration::from_secs(30)))\n                        .expect(\"TCP keepalive should be set\");\n\n                    let addr = stream\n                        .peer_addr()\n                        .expect(\"incoming connection should have an address\")\n                        .to_string();\n\n                    let mut connections = TCP_CONNECTIONS.lock();\n\n                    connections.insert(\n                        addr.clone(),","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi/src/process_command.rs#L131-L167","documentation":"listen_for_commands_tcp binds a TcpListener on 0.0.0.0:{port} (default 43663) and panics with this message if bind() fails. Common bind failures: the port is already in use by another komorebi instance or another program, or binding is blocked by permissions/policy.","triggerScenarios":"Calling main while a second komorebi instance is running, any other process listening on port 43663, or an OS-level restriction preventing the bind.","commonSituations":"Starting komorebi twice (e.g. duplicate autostart entries); port 43663 occupied by another app; leftover zombie komorebi.exe after a crash.","solutions":["Kill the existing komorebi.exe or other process using port 43663 (netstat -ano | findstr 43663)","Start komorebi with a different --port via CLI option","Remove duplicate autostart entries so only one instance launches","Check firewall/security software that may block socket binding"],"exampleFix":"// before\nlet listener = TcpListener::bind(format!(\"0.0.0.0:{port}\")).expect(\"could not start tcp server\");\n// after\nlet listener = match TcpListener::bind(format!(\"0.0.0.0:{port}\")) {\n    Ok(l) => l,\n    Err(e) => { tracing::error!(\"could not start tcp server on {port}: {e}\"); return; }\n};","handlingStrategy":"validation","validationCode":"// PowerShell: ensure port 43663 is free before starting\nnetstat -ano | Select-String ':43663 ' ; if ($?) { throw \"port 43663 in use\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure only one komorebi instance autostarts","Pick a non-default port via CLI if 43663 is occupied","Kill lingering komorebi.exe after crashes before relaunching"],"tags":["network","tcp","port","panic"],"backgroundTag":"address-already-in-use","analyzedSha":"e0709f02bfae4e503bf4640f58ee75ecbbfdbb97","analyzedAt":"2026-09-06T07:08:05.107Z","contentChangedAt":"2026-09-06T07:08:05.107Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}