davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
506 stars 146 forks source link

Socket.sendHeartbeat() EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) #253

Open michael-simonetta opened 6 months ago

michael-simonetta commented 6 months ago

Seeing an intermittent crash with SwiftPhoenixClient on Socket.sendHeartbeat()

Version: SwiftPhoenixClient 5.3.2

dsrees commented 6 months ago

do you have a stacktrace?

KaylaBrady commented 4 months ago

I have encountered this issue as well with the below stack trace

HeartbeatTimer.start (HeartbeatTimer.swift:81)
Socket.resetHeartbeat (Socket.swift:799)
Socket.onConnectionOpen (Socket.swift:660)
Socket.onOpen (Socket.swift:852)
Socket (<compiler-generated>:851)
URLSessionTransport.urlSession (PhoenixTransport.swift:248)
KaylaBrady commented 1 week ago

I have seen some other potentially related heartbeat errors:

EXC_BAD_ACCESS (KERN_INVALID_ADDRESS)
PhoenixTransport?
Socket.connectionState.getter (Socket.swift:243)
Socket.isConnected.getter (Socket.swift:238)
Socket.sendHeartbeat (Socket.swift:807)
closure in Socket.resetHeartbeat (Socket.swift:800)
SIGABRT
 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

Socket (<compiler-generated>:851)
Socket.onOpen (Socket.swift:852)
Socket.onConnectionOpen (Socket.swift:660)
Socket.resetHeartbeat (<compiler-generated>)

I haven't been able to reproduce locally, but one theory is that it may be from calling socket.onOpen in quick succession.

Socket.swift#L252 Checks if the socket is connected, but if the socket is in .connecting state, perhaps that creates some heartbeat-related race conditions when calling Socket.connect() in quick succession? The js client checks if the conn exists, not whether it has connected