Skip to content

Fix firstmover lock takeover on Windows - #112

Merged
ernestrc merged 3 commits into
unstablebuild:mainfrom
ejb711:fix-firstmover-lock-on-windows
Sep 30, 2026
Merged

ernestrc merged 3 commits into
unstablebuild:mainfrom
ejb711:fix-firstmover-lock-on-windows

Conversation

@ejb711

@ejb711 ejb711 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Part of Windows support (#68, coordinated on #81). Found by running a locally built rune.exe on
Windows 11; graphics stay with #82.

The firstmover lock is a unix socket. When a leader dies without removing it, the next process gets
an address-in-use error from bind(2) and falls back to following, then to a coup once the dead
leader stays unresponsive. That check used syscall.EADDRINUSE, which on Windows is an invented Go
errno rather than the Winsock WSAEADDRINUSE that bind returns, so the error was treated as
unexpected and the service gave up. After any run that did not exit cleanly, every storage user
failed on the next launch: session history, window size and position, installed packages.

Windows now also matches WSAEADDRINUSE, and the lock directory is created before the first bind,
since Windows reports a missing parent directory as WSAENETDOWN rather than ENOENT (same shape
as #111).

Linux and macOS are unchanged. New tests cover the per-OS check and, end to end, both a stale socket
left by a dead leader and a lock directory that does not exist yet. Verified natively: relaunching
on a data directory holding stale locks now logs the normal "Unresponsive leader, starting coup"
recovery instead of seven storage errors.

return true, err
}

if errors.Is(err, syscall.ENOENT) { // a component of the path does not exist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving MkdirAll out of the retry loop means the lock directory is created exactly once, at goroutine start. ENOENT is now absent from the expected-error set at line 862-864, so if Listen ever returns it, control falls into:

s.log(log.WarnLevel, "Unexpected error while trying to acquire lock %q: %v", ...)
return false, err

retry.Retry stops permanently on (false, err) (internal/extension/extensionv2/runner.go:244 doc), readyErr is set, and every subsequent Get/Set fails for the process lifetime. Before this PR the same
condition recreated the directory and retried.

Let's keep the MkdirAll but put it back inside fn, before cfg.Listen. It restores self-healing on
both platforms, and it still satisfies the Windows constraint the comment describes

ejb711 and others added 2 commits September 30, 2026 11:48
The lock is a unix socket. When a leader dies without removing it, the next process
gets an address-in-use error from bind(2) and falls back to following, then to a coup
once the dead leader stays unresponsive. That check used syscall.EADDRINUSE, which on
Windows is an invented Go errno rather than the Winsock WSAEADDRINUSE that bind
returns, so the error was treated as unexpected and the service gave up. After any run
that did not exit cleanly, every storage user failed on the next launch: session
history, window size and position, installed packages.

Match WSAEADDRINUSE as well on Windows, and create the lock directory before the first
bind, since Windows reports a missing parent directory as WSAENETDOWN rather than
ENOENT. Linux and macOS are unchanged: a new test covers both a stale socket left by a
dead leader and a lock directory that does not exist yet (unstablebuild#68).

Signed-off-by: Eric Brooks <[email protected]>
@ernestrc
ernestrc force-pushed the fix-firstmover-lock-on-windows branch from c9ca3eb to 37cab36 Compare September 30, 2026 12:08
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ernestrc
ernestrc merged commit 06ace17 into unstablebuild:main Sep 30, 2026
8 checks passed
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.

3 participants