-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: do not emit 'stop' watch event synchronously
Emits 'stop' event for fs.watchFile on process.nextTick to fix 'maximum call stack size exceeded' error when `stop` is called synchronously after listener is attached. PR-URL: #8524 Fixes: #8421 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ilkka Myller <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yorkie Liu <[email protected]>
- Loading branch information
1 parent
0f2f8ef
commit 1b97774
Showing
3 changed files
with
33 additions
and
1 deletion.
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,19 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
const watch = fs.watchFile(__filename, () => {}); | ||
let triggered; | ||
const listener = common.mustCall(() => { | ||
triggered = true; | ||
}); | ||
|
||
triggered = false; | ||
watch.once('stop', listener); // Should trigger. | ||
watch.stop(); | ||
assert.equal(triggered, false); | ||
setImmediate(() => { | ||
assert.equal(triggered, true); | ||
watch.removeListener('stop', listener); | ||
}); |
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,9 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
const watch = fs.watchFile(__filename, () => {}); | ||
watch.once('stop', assert.fail); // Should not trigger. | ||
watch.stop(); | ||
watch.removeListener('stop', assert.fail); |