Skip to content

Commit 8afd974

Browse files
committed
fix(rivetkit): fix initial hibernation state always being overridden with msgIndex of -1 (#3389)
1 parent d56daaf commit 8afd974

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

rivetkit-typescript/packages/rivetkit/src/drivers/engine/actor-driver.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,20 @@ export class EngineActorDriver implements ActorDriver {
181181
// Determine configuration for new WS
182182
let hibernationConfig: HibernationConfig;
183183
if (existingWs) {
184+
logger().debug({
185+
msg: "found existing hibernatable websocket",
186+
requestId: idToStr(requestId),
187+
lastMsgIndex: existingWs.msgIndex,
188+
});
184189
hibernationConfig = {
185190
enabled: true,
186191
lastMsgIndex: Number(existingWs.msgIndex),
187192
};
188193
} else {
194+
logger().debug({
195+
msg: "no existing hibernatable websocket found",
196+
requestId: idToStr(requestId),
197+
});
189198
if (path === PATH_CONNECT_WEBSOCKET) {
190199
hibernationConfig = {
191200
enabled: true,
@@ -251,12 +260,24 @@ export class EngineActorDriver implements ActorDriver {
251260
}
252261
}
253262

254-
// Save hibernatable WebSocket
255-
handler.actor[PERSIST_SYMBOL].hibernatableWebSocket.push({
256-
requestId,
257-
lastSeenTimestamp: BigInt(Date.now()),
258-
msgIndex: -1n,
259-
});
263+
// Save or update hibernatable WebSocket
264+
if (existingWs) {
265+
logger().debug({
266+
msg: "updated existing hibernatable websocket timestamp",
267+
requestId: idToStr(requestId),
268+
});
269+
existingWs.lastSeenTimestamp = BigInt(Date.now());
270+
} else {
271+
logger().debug({
272+
msg: "created new hibernatable websocket entry",
273+
requestId: idToStr(requestId),
274+
});
275+
handler.actor[PERSIST_SYMBOL].hibernatableWebSocket.push({
276+
requestId,
277+
lastSeenTimestamp: BigInt(Date.now()),
278+
msgIndex: -1n,
279+
});
280+
}
260281

261282
return hibernationConfig;
262283
},

0 commit comments

Comments
 (0)