Skip to content

Conversation

@yoheimuta
Copy link
Contributor

@yoheimuta yoheimuta commented Mar 3, 2025

Issue Link πŸ”—

Fixes #1052

Goals ⚽

This PR aims to fix a bug where isConnecting remains true indefinitely, preventing connect() from proceeding after a WebSocket peer closes.

As discussed in #1052, this occurs when:

  1. The device enters sleep mode (causing WebSocket closure).
  2. The server goes down during sleep.
  3. The app tries to reconnect, but isConnecting remains true, blocking new connections forever.

πŸ“ There are alternative steps to reproduce the issue, but this is the simplest method.
In other words, step 2 can be replaced by an extended sleep duration.

Additionally, this PR now includes a fix for another related scenario where isConnecting remains stuck when the WebSocket receives a waiting error.

Implementation Details 🚧

Fix for .peerClosed Issue

  • Ensures that isConnecting is properly reset to false when the WebSocket receives a .peerClosed event (introduced in #946).

Fix for .waiting(Error?) Issue

  • The waiting state now includes an optional error (case waiting(Error?)).
  • isConnecting is now reset to false when a waiting error is received.
  • This prevents the connection from getting stuck in an unusable state.

Testing βœ…

  • Reproduced both the peerClosed and waiting error issues using the SampleStarscream project.
  • Verified that connect() now proceeds correctly after .peerClosed and .waiting(error), allowing successful reconnections.
  • Checked logs with NSLog to confirm that isConnecting resets properly.

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.

WebSocket Cannot Reconnect When isConnecting Stays true Forever

1 participant