LGUG2Z/komorebi · error

could not connect to komorebi.sock

Error message

could not connect to komorebi.sock

What it means

Inside the static-config file watcher, on any config Modify/Remove event komorebi forwards the new bytes over a Unix domain socket at DATA_DIR/komorebi.sock, panicking if UnixStream::connect fails. This happens when no komorebi instance is listening on the socket (komorebi not running, stale socket file, or killed process).

Source

Thrown at komorebi/src/static_config.rs:1399

        #[allow(deprecated)]
        match value.focus_follows_mouse {
            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();

View on GitHub (pinned to e0709f02bf)

Solutions

  1. Start komorebi before (re)saving the config so a listener exists on the socket
  2. Delete the stale komorebi.sock file in DATA_DIR and restart komorebi
  3. Restart komorebic watch configuration after restarting komorebi
  4. Replace the expect with graceful error logging so the watcher survives a dead socket

Example fix

// before
UnixStream::connect(socket).expect("could not connect to komorebi.sock");
// after
if let Err(e) = UnixStream::connect(socket) {
    tracing::error!("could not connect to komorebi.sock: {e}");
    return;
}
Defensive patterns

Strategy: validation

Validate before calling

// confirm komorebi is listening before saving config / running komorebic watch
let sock = data_dir.join("komorebi.sock");
if !sock.exists() { eprintln!("komorebi not running: {sock:?} missing"); }

Prevention

When it happens

Trigger: Saving or touching the watched static config file while the socket at DATA_DIR/komorebi.sock does not exist or refuses connection — komorebi not running, crashed, or a stale .sock left behind.

Common situations: Editing komorebi.json while komorebi is stopped; a stale komorebi.sock after an unclean shutdown; the `komorebic watch` helper outliving the main process.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


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