Skip to content

fix: stop sync client busy loop after disconnect - #510

Open
gitwillsky wants to merge 1 commit into
1c3t3a:mainfrom
gitwillsky:fix/sync-client-poll-spin
Open

fix: stop sync client busy loop after disconnect#510
gitwillsky wants to merge 1 commit into
1c3t3a:mainfrom
gitwillsky:fix/sync-client-poll-spin

Conversation

@gitwillsky

Copy link
Copy Markdown

Summary

  • stop the synchronous callback worker when Engine.IO reaches a terminal state
  • only reconnect incomplete Engine.IO responses when reconnect is enabled
  • cover stopped sockets and transport errors with a focused unit test

Root cause

The synchronous client consumes its internal iterator on a background thread. When Engine.IO
stops, the iterator currently converts Ok(None) into another error item. With automatic
reconnect disabled, the callback loop ignores that error and polls the already-closed transport
again immediately. Each failed connection can therefore leave one busy-looping thread behind.

This change makes a stopped Engine.IO iterator terminal and explicitly stops the callback loop on
poll errors or namespace disconnects when reconnect is disabled. Normal packets do not acquire the
builder lock.

Validation

  • cargo check -p rust_socketio
  • cargo fmt --all -- --check
  • consumer reproduction before the fix: two failed connections produced two hot worker threads
    and 148-199% CPU
  • consumer reproduction after the fix: ten forced namespace disconnects remained at 0.0% CPU with
    a stable sleeping thread count

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.

1 participant