-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a timeout within a list of timeouts (that consists of only that specific timeout) throws during its execution, it's possible for the TimerWrap handle to become shared between both that list and an unref'd timeout created in the future. This fixes the bug by extending error handling in timeout execution to check for whether the current list is empty and if so do cleanup on it. PR-URL: #20497 Fixes: #19970 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
- Loading branch information
1 parent
1455b1d
commit a52f15e
Showing
2 changed files
with
64 additions
and
23 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
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,27 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// This test checks that throwing inside a setTimeout where that Timeout | ||
// instance is the only one within its list of timeouts, doesn't cause | ||
// an issue with an unref timeout scheduled in the error handler. | ||
// Refs: https://github.com/nodejs/node/issues/19970 | ||
|
||
const timeout = common.platformTimeout(50); | ||
|
||
const timer = setTimeout(common.mustNotCall(), 2 ** 31 - 1); | ||
|
||
process.once('uncaughtException', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'setTimeout Error'); | ||
|
||
const now = Date.now(); | ||
setTimeout(common.mustCall(() => { | ||
assert(Date.now() - now >= timeout); | ||
clearTimeout(timer); | ||
}), timeout).unref(); | ||
})); | ||
|
||
setTimeout(() => { | ||
throw new Error('setTimeout Error'); | ||
}, timeout); |