Repository navigation
Fix dropped messages on reused crash-handler pipe instances - #141
Merged
Merged
Conversation
After a pipe instance handled a message, the follow-up ReadFile failed with ERROR_BROKEN_PIPE (clients write one message and close), and DisconnectAndReconnect re-armed the instance. The code then fell through and overwrote that state with WRITING_STATE / fPendingIO = false, so the next client on that instance was never read: the server tried to write a 4-byte reply to the already-closed client, failed, and disconnected, discarding the message. With only 8 instances, any session with more than 8 messages started silently losing roughly every other message. When the lost message was obs-server's "unregister critical process" at shutdown, the crash-handler kept monitoring, treated normal renderer exits as a non-critical crash, and terminated the worker mid-shutdown. Stop overwriting the state after DisconnectAndReconnect and remove the now-unreachable WRITING_STATE handling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a Catch2 (v3.11.0, same as obs-studio-node) test executable that compiles socket-win.cpp and logger.cpp directly, so it needs none of the AWS SDK / Boost / zlib dependencies of crash-handler-process. The regression test sends 50 messages the way real clients do (open, write, close) to a uniquely named pipe, well above the 8 pipe instances, and checks every message arrives. Against the pre-fix socket code it receives only 29 of 50; with the fix it receives all 50. Tests are Windows-only and can be disabled with -DBUILD_TESTING=OFF. Catch2 adds no install rules as a subproject, and the test executable has no install() rule, so the release package is unchanged. The Windows CI job now runs ctest after the build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tryConnect() wrote the message with socket.write() and never closed the socket, so every register/unregister sent from Electron main left its connection open until the socket was garbage collected or the process exited. Each open connection holds one of the crash handler's 8 pipe instances: in a QA session, the four startup registrations held instances 0-3 for the whole session, leaving only four instances for every other message. If enough connections pile up, all instances are busy and clients get ERROR_PIPE_BUSY; obs-studio-node's writeCrashHandler does not retry, so its shutdown "unregister" could still be lost. Use socket.end(buffer) and destroy the socket once the write finishes. Checked with a local pipe server: 20 registrations previously left 20 connections open; now all 20 close and every message arrives in full. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests main.js unchanged against a Node pipe server standing in for
crash-handler-process. The native addon (loaded but unused by main.js)
and child_process.spawn are stubbed, so no native build or real process
is needed. Uses the built-in node:test runner; no new dependencies.
Covers:
- register/unregister messages arrive complete
- the client closes its connection after writing
- 20 messages leave no connections open
- retries until the pipe exists, delivering exactly once
- no resend after the server already received the message (a late
duplicate register after an unregister would re-watch the process)
Against the pre-fix main.js (socket.write without closing), 4 of the 5
tests fail ("still open: 20"); with the fix all 5 pass. The server
force-closes leftover connections so a regression fails instead of
hanging. Windows-only; the Windows CI job now runs it after ctest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The crash-handler tests remove the mock before it is used, causing later calls to invoke real external processes while spawn failures are only logged and suppressed.
1 open issue
What changed in this PR
This PR fixes message loss when Windows crash-handler pipe instances are reused and closes JavaScript client connections after sending messages.
Changes:
- Preserve the pipe’s reconnect state and remove obsolete reply-writing logic.
- Close JavaScript pipe connections after writes complete.
- Add C++ and JavaScript regression tests and run them in CI.
| File | Description |
|---|---|
tests/socket-win-tests.cpp |
Tests single-message delivery and pipe-instance reuse. |
tests/crash-handler-module.test.js |
Tests message contents, connection closure, and retries. |
tests/CMakeLists.txt |
Defines the Windows Catch2 test executable. |
crash-handler-process/platforms/socket-win.hpp |
Removes the obsolete writing-state constant. |
crash-handler-process/platforms/socket-win.cpp |
Preserves reconnect state and removes reply-writing logic. |
crash-handler-module/main.js |
Ends and destroys client connections after sending. |
CMakeLists.txt |
Adds Windows test configuration and Catch2 integration. |
.github/workflows/build.yml |
Runs C++ and JavaScript tests after building. |
Review effort: Balanced
main.js requires child_process inside startCrashHandler(), not at load time, but the Module._load stub was removed right after main.js loaded. Every usePipe() call therefore ran the real spawn() against C:\fake\...; it failed with the error logged and suppressed, so the tests passed while still attempting to launch a process (5 real spawn() calls per run). Mock child_process.spawn with node:test's mock.method for the suite and restore it in teardown. usePipe() now asserts the mock was called, so the test fails if the stub is ever bypassed again. Real spawn() calls per run: 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The spawn mock is restored before startCrashHandler() uses it, causing every test to attempt real process creation against a fake executable path while handled errors mask the broken isolation.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
summeroff
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

After a pipe instance handled a message, the follow-up ReadFile failed with
ERROR_BROKEN_PIPE(clients write one message and close), andDisconnectAndReconnectre-armed the instance. The code then fell through and overwrote that state withWRITING_STATE / fPendingIO = false, so the next client on that instance was never read: the server tried to write a 4-byte reply to the already-closed client, failed, and disconnected, discarding the message.With only 8 instances, any session with more than 8 messages started silently losing roughly every other message. When the lost message was obs-server's "unregister critical process" at shutdown, the crash-handler kept monitoring, treated normal renderer exits as a non-critical crash, and terminated the worker mid-shutdown.
Stop overwriting the state after
DisconnectAndReconnectand remove the now-unreachable WRITING_STATE handling.Close crash-handler pipe connections after writing from JS
Add Catch2 unit tests for
Socket_WINand run them in CIAdd node:test tests for crash-handler-module's pipe client
What happened
QA hit a shutdown crash in Streamlabs Desktop. In app.log, VideoSettingsService.shutdown never completes. That's the last line of the file:
[2026-11-21T00:25:04.642Z] [info] [worker] - [Shutdown] Starting VideoSettingsService.shutdown
The node-obs logs show no crash. This isn't a VideoSettingsService problem. The crash-handler killed the worker process during shutdown, and the root cause is a message-dropping bug in the crash-handler's Windows named-pipe server (
crash-handler-process/platforms/socket-win.cpp). The "unregister critical process" message sent at shutdown was lost. The crash-handler therefore kept monitoring, saw the child window's renderer exit normally, treated that as a "non-critical crash", and terminated every non-critical process, the worker included.VideoSettingsService was just the step running when the kill landed. obs64 never crashed, which is why the node-obs logs are clean