Skip to content

fix: prevent SSHTransport busy-loop on partial packets#179

Merged
vicajilau merged 3 commits into
masterfrom
fix/transport-partial-packet-busyloop
Jul 2, 2026
Merged

fix: prevent SSHTransport busy-loop on partial packets#179
vicajilau merged 3 commits into
masterfrom
fix/transport-partial-packet-busyloop

Conversation

@vicajilau

@vicajilau vicajilau commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #177.

SSHTransport._scheduleProcessData busy-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

_processPackets returns as soon as _consumePacket() cannot form a complete packet. But whenComplete reschedules 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 _hasNewData flag).

Also added a unit test to verify that the event loop is not starved when receiving a partial packet.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.85%. Comparing base (1d3ed4a) to head (b53960a).

Files with missing lines Patch % Lines
lib/src/ssh_transport.dart 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 54.85% <80.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
lib/src/ssh_transport.dart 52.58% <80.00%> (+1.66%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vicajilau vicajilau changed the title Fix/transport partial packet busyloop fix: prevent SSHTransport busy-loop on partial packets Jul 2, 2026
@vicajilau vicajilau merged commit 212074e into master Jul 2, 2026
3 checks passed
@vicajilau vicajilau deleted the fix/transport-partial-packet-busyloop branch July 2, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSHTransport busy-loops (100% CPU / ANR) on a partial packet in the read buffer

1 participant