davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
512 stars 147 forks source link

fix crashes from `Socket.connect` race conditions #260

Closed KaylaBrady closed 1 month ago

KaylaBrady commented 2 months ago

Includes fixes for two flavors of issues we've encountered in our SwiftUI application.

  1. https://github.com/davidstump/SwiftPhoenixClient/issues/253 This one I'm having trouble reproducing locally, but the Object 0x303285e60 of class HeartbeatTimer deallocated with non-zero retain count 3. This object's deinit, or something called from it, may have created a strong reference to self which outlived deinit, resulting in a dangling reference error especially had me thinking it was an issue with a strong reference in HeartbeatTimer. Please let me know if there is a good way to test this!

  2. https://github.com/davidstump/SwiftPhoenixClient/issues/258 - Error when receiving Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" Error messages

    • Only log failure error messages if self is not nil in PhoenixTransport.receive
    • Disconnect the existing connection in Socket.connect so that old connections are cleaned up.
    • Ignore errors due to normal cancellations

Tested these changes in an app that calls socket.connect() twice whenever returning from the background and confirmed onOpen callback only invoked once and onError not invoked.

ialimz commented 2 months ago

@ejensen would you please re-review this PR?

dsrees commented 1 month ago

5.3.4