Fix head-of-line blocking and resource leak in BidirectionalRelay#713
Open
mlsad3 wants to merge 5 commits intoapple:mainfrom
Open
Fix head-of-line blocking and resource leak in BidirectionalRelay#713mlsad3 wants to merge 5 commits intoapple:mainfrom
mlsad3 wants to merge 5 commits intoapple:mainfrom
Conversation
946f453 to
e3eeb21
Compare
jglogan
reviewed
May 1, 2026
af584de to
245e9ad
Compare
Replace synchronous write() calls with non-blocking I/O and DispatchSourceWrite backpressure in BidirectionalRelay. When a destination fd's buffer fills (e.g. during high container launch concurrency), the relay now suspends reading and installs a write source to drain pending data, instead of blocking the dispatch queue. Also remove the shared serial DispatchQueue from UnixSocketRelayManager so each BidirectionalRelay uses its own queue. Previously, a single blocked write on any connection would freeze ALL relay connections, including unrelated commands like `docker version`.
Resume suspended read sources before cancelling in stop(). GCD will not deliver cancel handlers on suspended dispatch sources, which caused file descriptor and memory leaks when connections were torn down while under backpressure. Also guard-unwrap buf.baseAddress in drainPendingWrite. Adds test for stop() while backpressured to verify cancel handlers fire.
245e9ad to
4105f64
Compare
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.
Replace synchronous
write()calls inBidirectionalRelaywith non-blocking I/O andDispatchSourceWritebackpressure handling. Under concurrent vsock proxy load, a single blocked write on the shared serial dispatch queue would freeze all relay connections permanently, including unrelated new connections.Closes #712
Changes
O_NONBLOCKand handleEAGAINby suspending reads and installing a write source to drain pending dataBidirectionalRelayits own serial queue instead of sharing one fromUnixSocketRelayManager, eliminating cross-connection blockingstop()— GCD does not deliver cancel handlers on suspended dispatch sources, which caused file descriptor and memory leaks on teardown under backpressurebuf.baseAddressindrainPendingWriteTest plan
Added
BidirectionalRelayTestswith 5 tests:EAGAIN→ write source drain → resume)waitForCompletion()resolves)Tested under sustained concurrent load that previously caused permanent hangs; verified normal operations work correctly after sustained load.