fix: stop realtime heartbeat from stacking and crashing on closed socket#1587
fix: stop realtime heartbeat from stacking and crashing on closed socket#1587yashs33244 wants to merge 1 commit into
Conversation
…hing on closed socket The realtime client cleared its heartbeat with clearTimeout even though the handle comes from setInterval, so the interval was never cancelled and a new one stacked on every reconnect. The interval body also called socket.send() with no readyState check, which throws INVALID_STATE_ERROR when the socket is CLOSING/CLOSED during a reconnect (e.g. after a background + network-drop + foreground cycle). Switch to clearInterval and only send the ping when the socket is OPEN, in both the web and react-native client templates.
Greptile SummaryThis PR fixes two related bugs in the realtime heartbeat logic present in both the web and React Native client templates:
Confidence Score: 4/5The two core changes are correct and address the reported crash; the only remaining gap is a minor timer leak on intentional disconnects that does no observable harm after this fix. Both template files are updated consistently, the root causes (wrong clear function, missing readyState check) are properly addressed, and the changes are minimal and targeted. The one gap — the heartbeat interval not being cancelled when the socket is permanently closed — is silent after this PR because the new readyState guard prevents any actual send, making it a cleanup suggestion rather than a functional regression. Both templates share the same minor gap in the Important Files Changed
|
The realtime client cleared its heartbeat with clearTimeout, but the handle comes from setInterval, so it was never cancelled - a new interval stacked on every reconnect. The interval also called socket.send() with no readyState check, which throws INVALID_STATE_ERROR when the socket is CLOSING/CLOSED during a reconnect (background + network drop + foreground cycle).
Switched to clearInterval and only send the ping when the socket is OPEN, in both the web and react-native client templates.
Reported against the React Native SDK (which is generated from these templates): appwrite/sdk-for-react-native#101