{"record":{"id":"7e3075f1fd22c7b3","repo":"LGUG2Z/komorebi","slug":"could-not-write-to-komorebi-sock","errorCode":null,"errorMessage":"could not write to komorebi.sock","messagePattern":"could not write to komorebi\\.sock","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"komorebi/src/static_config.rs","lineNumber":1402,"sourceCode":"            None => WindowsApi::disable_focus_follows_mouse()?,\n            Some(FocusFollowsMouseImplementation::Windows) => {\n                WindowsApi::enable_focus_follows_mouse()?;\n            }\n            Some(FocusFollowsMouseImplementation::Komorebi) => {}\n        };\n\n        let bytes = SocketMessage::ReloadStaticConfiguration(path.clone()).as_bytes()?;\n\n        wm.hotwatch.watch(path, move |event| match event.kind {\n            // Editing in Notepad sends a NoticeWrite while editing in (Neo)Vim sends\n            // a NoticeRemove, presumably because of the use of swap files?\n            EventKind::Modify(_) | EventKind::Remove(_) => {\n                let socket = DATA_DIR.join(\"komorebi.sock\");\n                let mut stream =\n                    UnixStream::connect(socket).expect(\"could not connect to komorebi.sock\");\n                stream\n                    .write_all(&bytes)\n                    .expect(\"could not write to komorebi.sock\");\n            }\n            _ => {}\n        })?;\n\n        Ok(wm)\n    }\n\n    pub fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()> {\n        let mut value = Self::read(path)?;\n        let mut wm = wm.lock();\n\n        let configs_with_preference: Vec<_> =\n            DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();\n        let mut configs_used = Vec::new();\n\n        let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();\n        workspace_matching_rules.clear();\n        drop(workspace_matching_rules);","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi/src/static_config.rs#L1384-L1420","documentation":"Immediately after connecting to komorebi.sock, the watcher writes the serialized config bytes with write_all and panics if the write fails. Typical causes: the remote side (komorebi) closed the connection mid-write (broken pipe), or the socket buffer/disconnected peer error.","triggerScenarios":"stream.write_all(&bytes) fails on the connected Unix socket — komorebi exited between connect and write, or the peer reset the connection while a config save was being forwarded.","commonSituations":"komorebi crashing exactly while a config file is saved; race where the socket connection is torn down as komorebi shuts down; rapid successive saves overwhelming the peer.","solutions":["Restart komorebi and re-save the config to confirm the socket peer is healthy","Delete any stale komorebi.sock and restart both komorebi and komorebic watch","Retry the config save once komorebi is confirmed running (check `komorebic state`)","Handle the write error gracefully (log + reconnect) instead of panicking in the watcher thread"],"exampleFix":"// before\nstream.write_all(&bytes).expect(\"could not write to komorebi.sock\");\n// after\nif let Err(e) = stream.write_all(&bytes) {\n    tracing::error!(\"could not write to komorebi.sock: {e}\");\n}","handlingStrategy":"retry","validationCode":"if !data_dir.join(\"komorebi.sock\").exists() { eprintln!(\"peer not up; retry after starting komorebi\"); }","typeGuard":null,"tryCatchPattern":"match stream.write_all(&bytes) {\n    Ok(()) => {},\n    Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => {\n        tracing::warn!(\"komorebi closed the socket; reconnecting...\");\n        // retry with a fresh UnixStream::connect\n    },\n    Err(e) => tracing::error!(\"write to komorebi.sock failed: {e}\"),\n}","preventionTips":["Avoid saving the config while komorebi is mid-shutdown","Rate-limit rapid successive config saves","Reconnect the socket rather than reusing a possibly-closed stream"],"tags":["unix-socket","ipc","panic","io"],"backgroundTag":"broken-pipe","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"}