Skip to content

fix(viewer): record socket ctime so a replaced socket cannot match - #433

Merged
ElbertePlinio merged 4 commits into
mainfrom
fix/404-viewer-socket-identity
Oct 29, 2026
Merged

ElbertePlinio merged 4 commits into
mainfrom
fix/404-viewer-socket-identity

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

The native viewer host records the identity of host.sock in host.json, and stop, prune, launch removal, requests and pulses use the socket only when it is the recorded one. That check compared ino and dev. ext4 gives a freed inode number to the next file created in the same directory, so a socket replaced at host.sock usually kept both, and stop or prune could unlink a socket that another process of the same user created there. GitHub runners keep /tmp on ext4, which made the "refuses dead readiness whose socket was replaced" test fail there; PR #400 had weakened that test until this fix.

host.json now also records the socket's ctime in nanoseconds, as a string from a bigint lstat taken after the host's chmod. Every check that trusts host.sock compares ino, dev and that ctime, through one helper in viewer-state.ts, still through the directory handle and under the session lock. A host.json from an older host has no ctime, so it is never trusted for requests. When its host is dead, removal deletes host.json and keeps the socket; the next start replaces a leftover socket at that path, so the session is not stuck.

Closes #404

Requirement Verified by Scenario and edge cases Result Evidence
Socket identity a replacement cannot share Tests that really replace the socket and record its real ino and dev, as ext4 does Stop and launch removal with a replaced socket; requests with a wrong or missing ctime Refused, socket kept; 4 new tests fail on the old source 404/before-old-source.log, 404/after-tests.log
Test replaces the socket on any filesystem and expects the refusal native-viewer.test.ts The #400 workaround is undone Passes on tmpfs; the recorded ino and dev reproduce the ext4 case native-viewer.test.ts
The request check covers the same identity (issue comment) native-viewer.test.ts Request, subscribe and pulse with a stale identity Refused native-viewer.test.ts
Older readiness without a ctime native-viewer.test.ts Dead older host with a listenerless socket left at the path, then a new start host.json removed, socket kept, the next start replaces it and records its own ctime native-viewer.test.ts

There is no separate QA pass: nothing user-visible changes, and the live native viewer tests run the real host and viewer.

Sol review: 9/10, no blocker or should. One nit, that the legacy restart test let Node remove the socket before the restart, is fixed in 4f5b2ce, so the leftover socket now stays through the restart.

Checks on 4f5b2ce (before the merge of main, which only brought the test fixes from #430): oxlint, typecheck, build; full vitest coverage run with the desktop, window, wait, browser and viewer requirements on (191 files, 3421 passed, 4 skipped); PICKFORGE_REQUIRE_XVFB=1 cargo test --workspace --locked (328 passed). PickCheck 0.4.0 against main is clean.

ext4 gives a freed inode number to the next file in the same directory, so
a socket replaced at host.sock usually keeps the recorded ino and dev.
host.json now also records the socket ctime in nanoseconds, and requests,
stop and launch removal compare it. Readiness from an older host without a
ctime never reaches a request, and its dead readiness is removed while the
socket stays for the next start to replace.

Closes #404
@ElbertePlinio
ElbertePlinio merged commit 45c4a71 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/404-viewer-socket-identity branch October 29, 2026 13:55
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.

viewer: socket identity check misses a replaced socket on ext4

1 participant