Skip to content

Commit 8872a11

Browse files
committed
fix(rivetkit): don't throw error if websocket is not open, causing realtime to break after a connection disconnects
1 parent 5d3cea0 commit 8872a11

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,19 @@ export interface ConnDriver<State> {
8383
const WEBSOCKET_DRIVER: ConnDriver<ConnDriverWebSocketState> = {
8484
sendMessage: (
8585
actor: AnyActorInstance,
86-
_conn: AnyConn,
86+
conn: AnyConn,
8787
state: ConnDriverWebSocketState,
8888
message: CachedSerializer<protocol.ToClient>,
8989
) => {
90+
if (state.websocket.readyState !== ConnReadyState.OPEN) {
91+
actor.rLog.warn({
92+
msg: "attempting to send message to closed websocket, this is likely a bug in RivetKit",
93+
connId: conn.id,
94+
wsReadyState: state.websocket.readyState,
95+
});
96+
return;
97+
}
98+
9099
const serialized = message.serialize(state.encoding);
91100

92101
actor.rLog.debug({

0 commit comments

Comments
 (0)