mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 03:38:43 +00:00
`waitForever()` is a public library export used by long-running embeds to
block until the host process is asked to exit. It called `interval.unref()`
on the keep-alive timer, which removes the timer from Node's active-handle
set. With no other ref'd handles, `await waitForever()` exits the process
in ~3ms with exit code 13 ("unsettled top-level await") instead of waiting.
Drop the `.unref()` so the interval actually keeps the loop alive, and
update the existing unit test (and comment) to lock in the new contract.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
14 lines
611 B
TypeScript
14 lines
611 B
TypeScript
export function waitForever() {
|
|
// Keep the event loop alive with a ref'd interval. A pending Promise is not
|
|
// an active handle on its own, so without the interval, Node exits the
|
|
// process with code 13 ("unsettled top-level await") as soon as nothing
|
|
// else is keeping the loop open — defeating the "wait forever" contract.
|
|
// The handle is intentionally not retained: there is no caller-visible way
|
|
// to stop a "forever" wait, and the interval lives for the lifetime of the
|
|
// process.
|
|
setInterval(() => {}, 1_000_000);
|
|
return new Promise<void>(() => {
|
|
/* never resolve */
|
|
});
|
|
}
|