Skip to content

fix(daemon): clear stale named pipe on Windows before bind (#723)#726

Open
GuruyuganKarthik8377 wants to merge 1 commit into
colbymchenry:mainfrom
GuruyuganKarthik8377:fix/windows-stale-named-pipe
Open

fix(daemon): clear stale named pipe on Windows before bind (#723)#726
GuruyuganKarthik8377 wants to merge 1 commit into
colbymchenry:mainfrom
GuruyuganKarthik8377:fix/windows-stale-named-pipe

Conversation

@GuruyuganKarthik8377

Copy link
Copy Markdown

Fixes #723

Root cause

The start() cleanup block that clears stale sockets before listen()
was gated to process.platform !== 'win32', so on Windows the stale
named pipe was never cleared. When Reasonix switches models and abruptly
disconnects, the old pipe lingers and the new daemon fails to bind with
EADDRINUSE.

Fix

Added probeAndClearWindowsPipe() — a fail-safe connect probe that runs
on Windows before listen().

  • ECONNREFUSED / ENOENT → pipe is stale, Windows releases the name, new daemon binds successfully
  • Connection succeeds → a live daemon is actually present, we leave it alone
  • Any error or timeout → treated as stale, startup is never blocked

Changes

  • src/mcp/daemon.ts only — no other files touched
  • POSIX path is completely untouched (existing unlinkSync block unchanged)
  • Mirrors the intent of the existing stale-socket comment, extended to Windows

Testing

  • Builds clean with npm run build
  • Cannot reproduce on macOS/Linux — zero risk to POSIX users

…nry#723)

On Windows, named pipes left over from an abruptly-disconnected daemon
(e.g. a Reasonix model-switch that sends EPIPE) cannot be unlinked like
POSIX sockets. The previous cleanup block was gated to non-Windows only,
so the stale pipe caused the next daemon's listen() to fail with
EADDRINUSE.

Fix: probe the pipe with a short connect attempt before listen(). A
refused or absent pipe means the name is stale and Windows will release
it; a successful connect means a live daemon is present and we leave it
alone. The probe always resolves — a timeout or unexpected error is
treated as stale so startup is never blocked.

Fixes colbymchenry#723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reasonix Desktop: model switch breaks codegraph daemon (EPIPE + stale named pipe on Windows)

1 participant