Repository navigation
fix: bound the MJPEG frames queued for a client that does not read them - #11
Merged
Merged
Conversation
Every frame was written to every MJPEG client with no timeout and no limit. GCDAsyncSocket keeps the writes that the socket cannot take in memory, so a client that stopped reading without closing its connection made WDA grow by the size of the stream (20-40 MB a minute) until iOS killed it and most processes of the device. - keep at most 4 frames in flight per client, drop the frames above it - disconnect a client that has not read any frame for 60 seconds - FBTCPSocket reports the completed writes to its delegate The same approach as appium#1227, for the GCDAsyncSocket server of this fork. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
FBMjpegServerwrites every frame to every client withwriteData:withTimeout:-1. GCDAsyncSocket keeps in memory every write the socket cannot take yet, with no limit. A client that stops reading but keeps its connection open makes WDA grow by the whole stream.This took iOS devices of MCloud offline. STF left its MJPEG request open after a user released the device (fixed in zebrunner/stf#1057). On an iPhone XR (iOS 18.7.10) WDA grew from 50 MB to 1.77 GB in 40 minutes with 2 such connections. iOS then killed most processes of the device (
testmanagerd, the tunnel), and WDA could not start again until a reboot.Fix
The same approach as upstream appium#1227, adapted to the GCDAsyncSocket server of this fork:
FBTCPSocketforwardssocket:didWriteDataWithTag:to its delegate (didClientWriteData:withTag:); the stream header and the frames use different tagsVerification
iOS 18.5 simulator, an animated page in Safari so that every frame changes. One client reads the stream, a second one sends the request and never reads (
SO_RCVBUF4 KB).phys_footprintof WebDriverAgentRunner-Runner:The reading client got the same number of frames in both runs (~770 frames / 79 MB in 136 s).
Log of this PR:
Built with Xcode 27.1 (
IPHONEOS_DEPLOYMENT_TARGET=15.0override, the project's 13.0 is no longer accepted by that Xcode); no new warnings.