Skip to content

Commit 5e6dda1

Browse files
fix(realtime): ensure WebSocket connections are properly closed in teardown (#1841)
1 parent d1ba7d9 commit 5e6dda1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/core/realtime-js/src/RealtimeClient.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,17 @@ export default class RealtimeClient {
595595
*/
596596
private _teardownConnection(): void {
597597
if (this.conn) {
598+
if (
599+
this.conn.readyState === SOCKET_STATES.open ||
600+
this.conn.readyState === SOCKET_STATES.connecting
601+
) {
602+
try {
603+
this.conn.close()
604+
} catch (e) {
605+
this.log('error', 'Error closing connection', e)
606+
}
607+
}
608+
598609
this.conn.onopen = null
599610
this.conn.onerror = null
600611
this.conn.onmessage = null

0 commit comments

Comments
 (0)