mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
fix(gmail-watcher): prevent TDZ in settleProcess and guard exit handler against stale child respawn
This commit is contained in:
committed by
Peter Steinberger
parent
2ffd7a7172
commit
94968c83c6
@@ -102,6 +102,10 @@ function spawnGogServe(cfg: GmailHookRuntimeConfig): ChildProcess {
|
||||
});
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
// If a newer watcher has replaced this child, do not respawn.
|
||||
if (watcherProcess !== null && watcherProcess !== child) {
|
||||
return;
|
||||
}
|
||||
if (shuttingDown) {
|
||||
return;
|
||||
}
|
||||
@@ -134,6 +138,8 @@ function spawnGogServe(cfg: GmailHookRuntimeConfig): ChildProcess {
|
||||
function settleProcess(proc: ChildProcess): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
let settled = false;
|
||||
let escalation: ReturnType<typeof setTimeout> | undefined;
|
||||
let finalTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
const settle = () => {
|
||||
if (settled) {
|
||||
return;
|
||||
@@ -150,7 +156,7 @@ function settleProcess(proc: ChildProcess): Promise<void> {
|
||||
|
||||
proc.kill("SIGTERM");
|
||||
|
||||
const escalation = setTimeout(() => {
|
||||
escalation = setTimeout(() => {
|
||||
try {
|
||||
proc.kill("SIGKILL");
|
||||
} catch {
|
||||
@@ -158,7 +164,7 @@ function settleProcess(proc: ChildProcess): Promise<void> {
|
||||
}
|
||||
}, 3_000);
|
||||
|
||||
const finalTimeout = setTimeout(() => {
|
||||
finalTimeout = setTimeout(() => {
|
||||
if (!settled) {
|
||||
log.warn("gog process did not exit after SIGKILL; giving up");
|
||||
settle();
|
||||
|
||||
Reference in New Issue
Block a user