Skip to content

Commit

Permalink
Be defensive against flushAndExit getting called twice (#30992)
Browse files Browse the repository at this point in the history
There's some evidence that this can get triggered twice (like multiple SIGINTs firing under certain configurations).

To ensure the cleanup functions only run once, I'm grabbing them + clearing them before we run them and hit the await points.

GitOrigin-RevId: b3b7953455dc32c2131133013d8d84ce5df4a013
  • Loading branch information
sshader authored and Convex, Inc. committed Oct 23, 2024
1 parent fac0ac2 commit 39c5662
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion npm-packages/convex/src/bundler/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ class OneoffContextImpl {
};
flushAndExit = async (exitCode: number, err?: any) => {
logVerbose(this, "Flushing and exiting");
const fns = Object.values(this._cleanupFns);
const cleanupFns = this._cleanupFns;
// Clear the cleanup functions so that there's no risk of running them twice
// if this somehow gets triggered twice.
this._cleanupFns = {};
const fns = Object.values(cleanupFns);
logVerbose(this, `Running ${fns.length} cleanup functions`);
for (const fn of fns) {
await fn();
Expand Down

0 comments on commit 39c5662

Please sign in to comment.