-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Race condition in Node.js - double resolve in close callback #5455
Copy link
Copy link
Closed
Description
Summary
The node close callback wrapper can call resolve() twice if a node's close handler both calls done() and throws an error.
Problem
In the close callback handling:
args.push(() => {
resolve();
});
try {
r = nodeCloseHandler.apply(node, args);
} catch(err) {
resolve();
}If the close handler calls done() (which calls resolve()) and then throws an error, resolve() is called twice.
Severity
LOW - While calling resolve twice on a Promise is a no-op, it indicates a logic issue that could cause confusion or issues in future refactoring.
Proposed Fix
Add a resolved flag:
var resolved = false;
args.push(() => {
if (!resolved) {
resolved = true;
resolve();
}
});
try {
r = nodeCloseHandler.apply(node, args);
} catch(err) {
if (!resolved) {
resolved = true;
resolve();
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels