Repository navigation
fix(desktop): tolerate a broken TCP state column in the Windows listener check - #26
Conversation
…ner check On some Windows builds the OS reports a listening socket with a wrong or empty TCP state (0, 1, 6, or unmapped), so the owner check's State = 2 predicate matched 0 rows even though the socket was listening and accepting connections. Startup then failed every time with listener_missing and the GUI blamed machine load. The listener query no longer filters on State: a row for the port owned by the process proves the bound socket, and rows owned by anyone else are tolerated as long as one row is ours. The token-authenticated handshake in connectBackground remains the identity proof, and a query returning no rows at all still reports listener_missing. Fixes w01fb0ss#15. Tests: new windows-background-security.test.ts pins the query and the row-matching order; 3 of its 5 tests fail against the old script. Full apps/desktop suite 108/108 pass; package typecheck and Biome clean. Signed-off-by: Rajnish Mani Tiwari <76885104+rajnishmanitiwari@users.noreply.github.com>
w01fb0ss
left a comment
There was a problem hiding this comment.
Thanks — this is a real startup blocker on Windows 26300 (#15), and dropping the State = 2 filter is the right fix: the state column isn't identity evidence.
One change before merging: please keep rejecting rows owned by other processes. The client sends its token as the first message, so the pre-connect owner check is what stops a second listener on the same loopback port from receiving it. A TIME_WAIT leftover from a dead predecessor is reported as owned by the System Idle/System process (0 or 4), so tolerating those is enough:
$foreign = @($listener | Where-Object { $p = [int]$_['OwningProcess']; $p -ne $processId -and $p -ne 0 -and $p -ne 4 })
if ($foreign.Count -gt 0) { throw 'listener_identity_changed' }
if (@($listener | Where-Object { [int]$_['OwningProcess'] -eq $processId }).Count -eq 0) { throw 'listener_identity_changed' }plus a test for "another process owns a row → rejected". I'll approve the CI run now.
The owner check now rejects a listener row owned by any process other than the background process, except the System Idle/System process (0 or 4): a second listener on the same loopback port would otherwise receive the token the client sends as its first message, and the pre-connect owner check is what stops that. A TIME_WAIT leftover from a dead predecessor is reported under PID 0 or 4, so tolerating those is enough. Addresses the review on w01fb0ss#26. Tests: new tests pin the foreign-row rejection and the System-process tolerance; 3 of 7 fail with the fix reverted. Full apps/desktop suite 110/110 pass; package typecheck and Biome clean. Signed-off-by: Rajnish Mani Tiwari <76885104+rajnishmanitiwari@users.noreply.github.com>
|
Thanks for the quick update — rejecting rows owned by other processes is exactly what we needed, and tolerating PID 0/4 for TIME_WAIT leftovers makes sense. Could you update the PR description (it still says rows owned by anyone else are tolerated)? Merging once CI is green; this will ship in v0.0.4. |
w01fb0ss
left a comment
There was a problem hiding this comment.
Approved: the listener check no longer depends on the TCP state column and still rejects other processes' rows.
Fixes #15. On some Windows builds the OS reports a listening socket with a wrong or empty TCP state (0, 1, 6, or unmapped), so the owner check's State = 2 predicate matched 0 rows even though the socket was listening and accepting connections. Startup then failed every time with listener_missing and the GUI blamed machine load. The listener query no longer filters on State: a row for the port owned by the process proves the bound socket, and rows owned by anyone else are tolerated as long as one row is ours. The token-authenticated handshake in connectBackground remains the identity proof, and a query returning no rows at all still reports listener_missing. Note: the GUI still shows the generic load message for a launch timeout; surfacing the check code to the user is a separate follow-up, not in this PR. Tests: new windows-background-security.test.ts pins the query and the row-matching order; 3 of its 5 tests fail against the old script. Full apps/desktop suite 108/108 pass; package typecheck and Biome clean.