-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timers: fix leak when interpreter shutsdown early
If something creates an unhandled rejection condition we'll end up with timers being kept alive in C without a way to recover them. Fix it by keeping the strong reference in JS, so it all goes away when we destroy the runtime.
- Loading branch information
Showing
8 changed files
with
15,088 additions
and
15,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ src/js/std.js | |
src/version.h | ||
node_modules/ | ||
docs/api/ | ||
test_dir*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const core = globalThis.__bootstrap; | ||
|
||
const timers = new Set(); | ||
|
||
globalThis.setTimeout = (fn, ms) => { | ||
const t = core.setTimeout(fn, ms); | ||
|
||
timers.add(t); | ||
|
||
return t; | ||
}; | ||
|
||
globalThis.clearTimeout = t => { | ||
core.clearTimeout(t); | ||
timers.delete(t); | ||
}; | ||
|
||
globalThis.setInterval = (fn, ms) => { | ||
const t = core.setInterval(fn, ms); | ||
|
||
timers.add(t); | ||
|
||
return t; | ||
}; | ||
|
||
globalThis.clearInterval = t => { | ||
core.clearInterval(t); | ||
timers.delete(t); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
async function foo() { | ||
throw new Error('oops!'); | ||
} | ||
|
||
|
||
setTimeout(async () => { | ||
await foo(); | ||
}, 100); | ||
|
||
|
||
setTimeout(() => { | ||
console.log('boooo!'); | ||
}, 99999); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import assert from 'tjs:assert'; | ||
import path from 'tjs:path'; | ||
|
||
|
||
const args = [ | ||
tjs.exepath, | ||
'run', | ||
path.join(import.meta.dirname, 'helpers', 'timers.js') | ||
]; | ||
const proc = tjs.spawn(args, { stdout: 'ignore', stderr: 'pipe' }); | ||
const buf = new Uint8Array(4096); | ||
const nread = await proc.stderr.read(buf); | ||
const stderrStr = new TextDecoder().decode(buf.subarray(0, nread)); | ||
const status = await proc.wait(); | ||
assert.ok(stderrStr.match(/Error: oops!/) !== null, 'dumps to stderr'); | ||
assert.ok(status.exit_status !== 0 && status.term_signal === null, 'succeeded'); |