openzca 0.1.20 → 0.1.21
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/cli.js +71 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -820,6 +820,66 @@ function isListenerAlreadyStarted(error) {
|
|
|
820
820
|
function toErrorText(error) {
|
|
821
821
|
return error instanceof Error ? error.message : String(error);
|
|
822
822
|
}
|
|
823
|
+
var SHUTDOWN_CALLBACKS = /* @__PURE__ */ new Set();
|
|
824
|
+
var shutdownSignalReceived = null;
|
|
825
|
+
var shutdownRunning = false;
|
|
826
|
+
function signalExitCode(signal) {
|
|
827
|
+
if (signal === "SIGINT") return 130;
|
|
828
|
+
if (signal === "SIGTERM") return 143;
|
|
829
|
+
return 1;
|
|
830
|
+
}
|
|
831
|
+
function registerShutdownCallback(callback) {
|
|
832
|
+
SHUTDOWN_CALLBACKS.add(callback);
|
|
833
|
+
return () => {
|
|
834
|
+
SHUTDOWN_CALLBACKS.delete(callback);
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
async function runShutdownCallbacks(signal) {
|
|
838
|
+
if (shutdownRunning) return;
|
|
839
|
+
shutdownRunning = true;
|
|
840
|
+
const callbacks = Array.from(SHUTDOWN_CALLBACKS);
|
|
841
|
+
SHUTDOWN_CALLBACKS.clear();
|
|
842
|
+
writeDebugLine(
|
|
843
|
+
"process.signal",
|
|
844
|
+
{
|
|
845
|
+
signal,
|
|
846
|
+
callbackCount: callbacks.length
|
|
847
|
+
},
|
|
848
|
+
void 0
|
|
849
|
+
);
|
|
850
|
+
for (const callback of callbacks) {
|
|
851
|
+
try {
|
|
852
|
+
await Promise.resolve(callback());
|
|
853
|
+
} catch (error) {
|
|
854
|
+
writeDebugLine(
|
|
855
|
+
"process.signal.callback_error",
|
|
856
|
+
{
|
|
857
|
+
signal,
|
|
858
|
+
message: toErrorText(error)
|
|
859
|
+
},
|
|
860
|
+
void 0
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function installSignalHandler(signal) {
|
|
866
|
+
process.on(signal, () => {
|
|
867
|
+
if (shutdownSignalReceived) return;
|
|
868
|
+
shutdownSignalReceived = signal;
|
|
869
|
+
const exitCode = signalExitCode(signal);
|
|
870
|
+
const forceExitMs = parsePositiveIntFromEnv("OPENZCA_SIGNAL_FORCE_EXIT_MS", 1500);
|
|
871
|
+
const forceTimer = setTimeout(() => {
|
|
872
|
+
process.exit(exitCode);
|
|
873
|
+
}, forceExitMs);
|
|
874
|
+
forceTimer.unref();
|
|
875
|
+
void runShutdownCallbacks(signal).finally(() => {
|
|
876
|
+
clearTimeout(forceTimer);
|
|
877
|
+
process.exit(exitCode);
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
installSignalHandler("SIGINT");
|
|
882
|
+
installSignalHandler("SIGTERM");
|
|
823
883
|
async function withTimeout(task, timeoutMs, message) {
|
|
824
884
|
let timeoutId;
|
|
825
885
|
try {
|
|
@@ -871,6 +931,9 @@ async function withUploadListener(api, command, task) {
|
|
|
871
931
|
12e4
|
|
872
932
|
);
|
|
873
933
|
let startedHere = false;
|
|
934
|
+
const unregisterSignalCleanup = registerShutdownCallback(async () => {
|
|
935
|
+
await stopUploadListenerSafely(api, command);
|
|
936
|
+
});
|
|
874
937
|
const sinkError = (error) => {
|
|
875
938
|
writeDebugLine(
|
|
876
939
|
"msg.upload.listener.error",
|
|
@@ -961,6 +1024,7 @@ async function withUploadListener(api, command, task) {
|
|
|
961
1024
|
if (startedHere) {
|
|
962
1025
|
await stopUploadListenerSafely(api, command);
|
|
963
1026
|
}
|
|
1027
|
+
unregisterSignalCleanup();
|
|
964
1028
|
api.listener.off("error", sinkError);
|
|
965
1029
|
api.listener.off("closed", sinkClosed);
|
|
966
1030
|
}
|
|
@@ -3258,6 +3322,8 @@ ${replyContextText}` : replyContextText;
|
|
|
3258
3322
|
let recycleForceExitTimer = null;
|
|
3259
3323
|
let heartbeatTimer = null;
|
|
3260
3324
|
let recyclePendingExit = false;
|
|
3325
|
+
let unregisterShutdown = () => {
|
|
3326
|
+
};
|
|
3261
3327
|
const finish = () => {
|
|
3262
3328
|
if (settled) return;
|
|
3263
3329
|
settled = true;
|
|
@@ -3273,6 +3339,9 @@ ${replyContextText}` : replyContextText;
|
|
|
3273
3339
|
clearInterval(heartbeatTimer);
|
|
3274
3340
|
heartbeatTimer = null;
|
|
3275
3341
|
}
|
|
3342
|
+
unregisterShutdown();
|
|
3343
|
+
unregisterShutdown = () => {
|
|
3344
|
+
};
|
|
3276
3345
|
resolve();
|
|
3277
3346
|
};
|
|
3278
3347
|
api.listener.on("closed", (code, reason) => {
|
|
@@ -3295,13 +3364,14 @@ ${replyContextText}` : replyContextText;
|
|
|
3295
3364
|
finish();
|
|
3296
3365
|
}
|
|
3297
3366
|
});
|
|
3298
|
-
const
|
|
3367
|
+
const onSignal = () => {
|
|
3299
3368
|
try {
|
|
3300
3369
|
api.listener.stop();
|
|
3301
3370
|
} catch {
|
|
3302
3371
|
}
|
|
3303
3372
|
finish();
|
|
3304
3373
|
};
|
|
3374
|
+
unregisterShutdown = registerShutdownCallback(onSignal);
|
|
3305
3375
|
if (lifecycleEventsEnabled && heartbeatMs > 0) {
|
|
3306
3376
|
heartbeatTimer = setInterval(() => {
|
|
3307
3377
|
emitLifecycle("heartbeat");
|
|
@@ -3336,7 +3406,6 @@ ${replyContextText}` : replyContextText;
|
|
|
3336
3406
|
finish();
|
|
3337
3407
|
}, recycleMs);
|
|
3338
3408
|
}
|
|
3339
|
-
process.once("SIGINT", onSigint);
|
|
3340
3409
|
api.listener.start({ retryOnClose: supervised ? false : Boolean(opts.keepAlive) });
|
|
3341
3410
|
});
|
|
3342
3411
|
}
|