LGUG2Z/komorebi · error

could not write to komorebi.sock

Error message

could not write to komorebi.sock

What it means

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.

Source

Thrown at komorebi/src/static_config.rs:1402

            None => WindowsApi::disable_focus_follows_mouse()?,
            Some(FocusFollowsMouseImplementation::Windows) => {
                WindowsApi::enable_focus_follows_mouse()?;
            }
            Some(FocusFollowsMouseImplementation::Komorebi) => {}
        };

        let bytes = SocketMessage::ReloadStaticConfiguration(path.clone()).as_bytes()?;

        wm.hotwatch.watch(path, move |event| match event.kind {
            // Editing in Notepad sends a NoticeWrite while editing in (Neo)Vim sends
            // a NoticeRemove, presumably because of the use of swap files?
            EventKind::Modify(_) | EventKind::Remove(_) => {
                let socket = DATA_DIR.join("komorebi.sock");
                let mut stream =
                    UnixStream::connect(socket).expect("could not connect to komorebi.sock");
                stream
                    .write_all(&bytes)
                    .expect("could not write to komorebi.sock");
            }
            _ => {}
        })?;

        Ok(wm)
    }

    pub fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()> {
        let mut value = Self::read(path)?;
        let mut wm = wm.lock();

        let configs_with_preference: Vec<_> =
            DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
        let mut configs_used = Vec::new();

        let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
        workspace_matching_rules.clear();
        drop(workspace_matching_rules);

View on GitHub (pinned to e0709f02bf)

Solutions

  1. Restart komorebi and re-save the config to confirm the socket peer is healthy
  2. Delete any stale komorebi.sock and restart both komorebi and komorebic watch
  3. Retry the config save once komorebi is confirmed running (check `komorebic state`)
  4. Handle the write error gracefully (log + reconnect) instead of panicking in the watcher thread

Example fix

// before
stream.write_all(&bytes).expect("could not write to komorebi.sock");
// after
if let Err(e) = stream.write_all(&bytes) {
    tracing::error!("could not write to komorebi.sock: {e}");
}
Defensive patterns

Strategy: retry

Validate before calling

if !data_dir.join("komorebi.sock").exists() { eprintln!("peer not up; retry after starting komorebi"); }

Try / catch

match stream.write_all(&bytes) {
    Ok(()) => {},
    Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => {
        tracing::warn!("komorebi closed the socket; reconnecting...");
        // retry with a fresh UnixStream::connect
    },
    Err(e) => tracing::error!("write to komorebi.sock failed: {e}"),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06). Data as JSON: /api/errors/7e3075f1fd22c7b3. Report an issue: GitHub.