From 43ed3363ef2eaa53cae025b420b62e7a570f68a0 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sun, 2 Nov 2025 13:15:45 -0700 Subject: [PATCH] fix(rivetkit): don't throw error if websocket is not open, causing realtime to break after a connection disconnects --- .../packages/rivetkit/src/actor/conn-drivers.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts b/rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts index e68456a5ba..c0a4c276e4 100644 --- a/rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts +++ b/rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts @@ -83,10 +83,19 @@ export interface ConnDriver { const WEBSOCKET_DRIVER: ConnDriver = { sendMessage: ( actor: AnyActorInstance, - _conn: AnyConn, + conn: AnyConn, state: ConnDriverWebSocketState, message: CachedSerializer, ) => { + if (state.websocket.readyState !== ConnReadyState.OPEN) { + actor.rLog.warn({ + msg: "attempting to send message to closed websocket, this is likely a bug in RivetKit", + connId: conn.id, + wsReadyState: state.websocket.readyState, + }); + return; + } + const serialized = message.serialize(state.encoding); actor.rLog.debug({