Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v18.x backport] fs: fix nonNativeWatcher leak of StatWatchers #46031

Closed
wants to merge 2 commits into from

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Dec 31, 2022

backport of
#45500
#45501

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. v18.x Issues that can be reproduced on v18.x or PRs targeting the v18.x-staging branch. labels Dec 31, 2022
@MoLow
Copy link
Member Author

MoLow commented Dec 31, 2022

CC @danielleadams


const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', common.mustCallAtLeast(function(event, filename) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
watcher.on('change', common.mustCallAtLeast(function(event, filename) {
watcher.on('change', common.mustCallAtLeast((event, filename) => {

const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', common.mustCallAtLeast(function(event, filename) {
// Libuv inconsistenly emits a rename event for the file we are watching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Libuv inconsistenly emits a rename event for the file we are watching
// Libuv inconsistently emits a rename event for the file we are watching

await setTimeout(common.platformTimeout(100));
fs.writeFileSync(testFile, 'hello');

process.once('exit', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.once('exit', function() {
process.once('exit', () => {

assert(!process._getActiveHandles().some((handle) => handle.constructor.name === 'StatWatcher'));
}));

process.on('exit', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.on('exit', function() {
process.on('exit', () => {

await setTimeout(common.platformTimeout(100));
fs.writeFileSync(testFile, 'hello');

process.once('exit', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also probably move this up a bit so that the handler is added before we start doing anything else like waiting for timers or writing to files.

@MoLow
Copy link
Member Author

MoLow commented Dec 31, 2022

@mscdex this is a backport PR, changing existing tests code will make further backporting harder since it will introduce even more conflict

@aduh95 aduh95 changed the title fs: fix nonNativeWatcher leak of StatWatchers [v18.x backport] fs: fix nonNativeWatcher leak of StatWatchers Jan 1, 2023
@aduh95
Copy link
Contributor

aduh95 commented Jan 1, 2023

@MoLow it is recommended to specify in the PR title that it is a backport so it's easier to spot and review accordingly.

@danielleadams danielleadams force-pushed the v18.x-staging branch 2 times, most recently from 2098d7a to bac6b7d Compare January 4, 2023 17:10
PR-URL: nodejs#45501
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: nodejs#45500
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@BethGriggs BethGriggs added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 19, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 19, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. v18.x Issues that can be reproduced on v18.x or PRs targeting the v18.x-staging branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants