Repository navigation
fix(provider): cancel the pending reconnect on disconnect() and destroy() - #1183
Conversation
…oy() onClose schedules a reconnect with setTimeout but dropped the handle, so calling disconnect() or destroy() within `delay` of a close could not stop it: the timer called connect(), set shouldConnect back to true and opened a socket nobody asked for. Keep the timer handle and clear it in disconnect() (which destroy() calls) and at the start of connect(). Fixes ueberdosis#1182
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 SummaryThe websocket provider now stores pending reconnect timers and clears them when New tests check that both teardown methods stop the reconnect and keep WalkthroughThe websocket now tracks delayed reconnects and clears the pending timer during connection setup and disconnect. Tests verify that ChangesWebsocket reconnect cancellation
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested labels: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk remains in the reviewed reconnect cancellation change. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #1182
Problem
When an established connection closes,
HocuspocusProviderWebsocket.onCloseschedules a reconnect withsetTimeout, but the handle was dropped. Callingdisconnect()ordestroy()withindelayof the close could not cancel it: the timer calledconnect(), which setshouldConnectback totrueand opened a new socket. Afterdestroy(), nothing listened to that socket or closed it.Fix
reconnectTimeout.disconnect()(whichdestroy()also calls) and at the start ofconnect(), so a manualconnect()doesn't leave a second one pending.Tests
Added
tests/providerwebsocket/reconnectTimer.ts, based on the reproduction in the issue. For bothdisconnect()anddestroy(), it opens a fake socket, closes it from the server side, tears down withindelay, and checks that no second socket is created andshouldConnectstaysfalse. Both cases fail without the fix and pass with it.tests/providerandtests/providerwebsocketpass (73 tests) on Node 22.