@rivetkit/engine-runner 2.0.37 → 2.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +19 -22
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.js +19 -22
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/mod.ts +23 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/engine-runner",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"pino": "^9.9.5",
|
|
23
23
|
"ws": "^8.18.3",
|
|
24
24
|
"@rivetkit/virtual-websocket": "2.0.33",
|
|
25
|
-
"@rivetkit/engine-runner-protocol": "2.0.
|
|
25
|
+
"@rivetkit/engine-runner-protocol": "2.0.38"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^22.18.1",
|
package/src/mod.ts
CHANGED
|
@@ -205,7 +205,6 @@ export class Runner {
|
|
|
205
205
|
runnerId?: string;
|
|
206
206
|
#started: boolean = false;
|
|
207
207
|
#shutdown: boolean = false;
|
|
208
|
-
#shuttingDown: boolean = false;
|
|
209
208
|
#reconnectAttempt: number = 0;
|
|
210
209
|
#reconnectTimeout?: NodeJS.Timeout;
|
|
211
210
|
|
|
@@ -480,20 +479,19 @@ export class Runner {
|
|
|
480
479
|
// MARK: Shutdown
|
|
481
480
|
async shutdown(immediate: boolean, exit: boolean = false) {
|
|
482
481
|
// Prevent concurrent shutdowns
|
|
483
|
-
if (this.#
|
|
482
|
+
if (this.#shutdown) {
|
|
484
483
|
this.log?.debug({
|
|
485
484
|
msg: "shutdown already in progress, ignoring",
|
|
486
485
|
});
|
|
487
486
|
return;
|
|
488
487
|
}
|
|
489
|
-
this.#
|
|
488
|
+
this.#shutdown = true;
|
|
490
489
|
|
|
491
490
|
this.log?.info({
|
|
492
491
|
msg: "starting shutdown",
|
|
493
492
|
immediate,
|
|
494
493
|
exit,
|
|
495
494
|
});
|
|
496
|
-
this.#shutdown = true;
|
|
497
495
|
|
|
498
496
|
// Clear reconnect timeout
|
|
499
497
|
if (this.#reconnectTimeout) {
|
|
@@ -886,7 +884,7 @@ export class Runner {
|
|
|
886
884
|
|
|
887
885
|
ws.addEventListener("error", (ev) => {
|
|
888
886
|
this.log?.error({
|
|
889
|
-
msg: `WebSocket error: ${ev.error}`,
|
|
887
|
+
msg: `WebSocket error: ${stringifyError(ev.error)}`,
|
|
890
888
|
});
|
|
891
889
|
|
|
892
890
|
if (!this.#shutdown) {
|
|
@@ -918,22 +916,17 @@ export class Runner {
|
|
|
918
916
|
});
|
|
919
917
|
|
|
920
918
|
ws.addEventListener("close", async (ev) => {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
closeError?.group === "ws" &&
|
|
924
|
-
closeError?.error === "eviction"
|
|
925
|
-
) {
|
|
926
|
-
this.log?.info("runner websocket evicted");
|
|
927
|
-
|
|
928
|
-
this.#config.onDisconnected(ev.code, ev.reason);
|
|
929
|
-
|
|
930
|
-
await this.shutdown(true);
|
|
931
|
-
} else {
|
|
919
|
+
if (!this.#shutdown) {
|
|
920
|
+
const closeError = parseWebSocketCloseReason(ev.reason);
|
|
932
921
|
if (
|
|
933
|
-
closeError?.group === "
|
|
934
|
-
closeError?.error === "
|
|
922
|
+
closeError?.group === "ws" &&
|
|
923
|
+
closeError?.error === "eviction"
|
|
935
924
|
) {
|
|
936
|
-
this.log?.info("runner
|
|
925
|
+
this.log?.info("runner websocket evicted");
|
|
926
|
+
|
|
927
|
+
this.#config.onDisconnected(ev.code, ev.reason);
|
|
928
|
+
|
|
929
|
+
await this.shutdown(true);
|
|
937
930
|
} else {
|
|
938
931
|
this.log?.warn({
|
|
939
932
|
msg: "runner disconnected",
|
|
@@ -941,18 +934,16 @@ export class Runner {
|
|
|
941
934
|
reason: ev.reason.toString(),
|
|
942
935
|
closeError,
|
|
943
936
|
});
|
|
944
|
-
}
|
|
945
937
|
|
|
946
|
-
|
|
947
|
-
|
|
938
|
+
this.#config.onDisconnected(ev.code, ev.reason);
|
|
939
|
+
}
|
|
948
940
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
941
|
+
// Clear ack interval on close
|
|
942
|
+
if (this.#ackInterval) {
|
|
943
|
+
clearInterval(this.#ackInterval);
|
|
944
|
+
this.#ackInterval = undefined;
|
|
945
|
+
}
|
|
954
946
|
|
|
955
|
-
if (!this.#shutdown) {
|
|
956
947
|
// Start runner lost timeout if we have a threshold and are not shutting down
|
|
957
948
|
if (
|
|
958
949
|
!this.#runnerLostTimeout &&
|
|
@@ -977,6 +968,10 @@ export class Runner {
|
|
|
977
968
|
|
|
978
969
|
// Attempt to reconnect if not stopped
|
|
979
970
|
this.#scheduleReconnect();
|
|
971
|
+
} else {
|
|
972
|
+
this.log?.info("websocket closed");
|
|
973
|
+
|
|
974
|
+
this.#config.onDisconnected(ev.code, ev.reason);
|
|
980
975
|
}
|
|
981
976
|
});
|
|
982
977
|
}
|