fix: prevent SSHTransport busy-loop on partial packets#179
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #179 +/- ##
==========================================
+ Coverage 54.67% 54.85% +0.18%
==========================================
Files 66 66
Lines 5419 5423 +4
==========================================
+ Hits 2963 2975 +12
+ Misses 2456 2448 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Fixes #177.
SSHTransport._scheduleProcessDatabusy-loops at 100% CPU whenever a partial packet is left in the read buffer, permanently starving the event loop (and the socket reads that would complete the packet). On Flutter this pegs the platform thread and produces an "Input dispatching timed out" ANR / frozen UI.Root Cause
_processPacketsreturns as soon as_consumePacket()cannot form a complete packet. ButwhenCompletereschedules whenever_buffer.isNotEmpty, even when the pass consumed nothing. The reschedule runs as a microtask; microtasks have priority over I/O events, so the loop starves_onSocketData— the additional bytes needed to complete the packet are never delivered, and it spins forever.Fix
Only reschedule when the pass actually made progress (a packet was consumed) or new bytes arrived while processing (tracked by a new
_hasNewDataflag).Also added a unit test to verify that the event loop is not starved when receiving a partial packet.