pusher / NWWebSocket

A WebSocket client written in Swift, using the Network framework from Apple.
MIT License
123 stars 25 forks source link

Fix reconnection loops #44

Closed alvaro-delacruz-bat closed 9 months ago

alvaro-delacruz-bat commented 1 year ago

Description of the pull request

Enhanced the migrate connection code to resolve issues with NWConnection leaks. Additionally, implemented validation measures to avert the occurrence of reconnection loops.

Why is the change necessary?

Certain modifications have been implemented to address memory leaks during the execution of the migrateConnection function. However, the key alteration revolves around cases where the NWConnection instance on iOS is unexpectedly disposed of. In such instances, regardless of the number of reconnection attempts, they are destined to fail due to the connection's disposal. To counteract this situation, a safeguard has been introduced to detect entry into this reconnection loop. Consequently, the connection is deliberately dismantled, paving the way for the establishment of a fresh NWConnection instance, enabling subsequent reconnection attempts to succeed.