Repository navigation
Never cancel a Snoop pipe frame write partway - #10
Merged
Merged
Conversation
A pipe write that does not fit the pipe's buffer stays pending until the reader takes the bytes. Under Wine that is every write, because .NET creates the pipe with a zero-size buffer. When the per-call timeout or a caller's token cancelled a pending write, the reader had already taken the length prefix but never got the body. It then read the next frame's bytes as the rest of this one, failed to parse them, and closed the pipe, so the broker lost the session while the target kept running. SendAsync now writes the prefix and body in one write that is never cancelled, and holds the write lock until it finishes. The token still bounds the caller's wait. A timed-out send in the proxy now reports OperationTimedOut and sends a cancel frame, like a timed-out response. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Nd32EDa2xhc9FzL1Vp3NJU
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.
Problem
The broker could lose its Snoop session while the target app kept running. Every later call then failed with
SESSION_NOT_FOUND.FramedJsonTransport.SendAsyncsent each frame as two writes: the 4-byte length prefix, then the JSON body. Both writes used the caller's token, which inPipeSnoopInspectorProxyis the 10 s per-call timeout. A pipe write stays pending until the reader takes the bytes. .NET creates the pipe with a zero-size buffer, so this applies to every write. When the agent read slowly, the timeout could cancel the body write after the agent had already read the prefix. The unread body bytes were lost. The agent then read the next frame's bytes as the rest of the old one, failed to parse them and closed the pipe.ResponsePumpAsyncsaw the end of the stream and marked the session disconnected.Windows and Wine handle pending pipe writes the same way. Wine is slower, so the timeout fires more often there.
Fix
FramedJsonTransport.SendAsyncbuilds one buffer holding the prefix and the body, and writes it in a single write withCancellationToken.None. The write lock is held until that write finishes. The caller's token now only limits how long the caller waits.PipeSnoopInspectorProxy.InvokeAsyncsends inside thetry, so a send that times out reportsOperationTimedOutand sends a cancel frame, as a timed-out response already did.SendAsync_CancelledWhileWritePending_StillWritesWholeFrameuses a stream that stalls the write. It fails on the old transport (JsonExceptionat byte 1) and passes with the fix. All 12 transport tests pass.Testing
All runs were under Wine on Linux. Nothing was tested on Windows.
Real MotionCatalyst, headless, with the same build, hive and Wine. Only the broker's
SnoopWPF.Agent.Remote.dllchanged between runs. Each freeze round stopped the MC process (SIGSTOP) for 13 s during a call, resumed it, then made 5 more calls.With the change, each frozen call returned
OPERATION_TIMED_OUT, then all 5 later calls worked.A stress harness running the real transport under Wine broke the frame stream in 3 of 3 runs before the change, and in 0 of 3 runs with it.
The unit test proves the frame tear itself. In real MotionCatalyst the test shows the session drop before the change and no drop after it.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Nd32EDa2xhc9FzL1Vp3NJU
Agent: wine-snoop (subagent of linux-wine) on oystein-office-primary