Skip to content

Issue with fs-watch tests on macOS with incoming [email protected] release #54450

@santigimeno

Description

@santigimeno

We're in the process of releasing [email protected]. While running the libuv-in-node CI bot, many of the fs-watch tests in macOS have become very flaky. It looks like the root of the problem comes from how fsevents on macOS are handled (explanation here and here), though these issues have become more apparent after a change in libuv which fixed some other issues such as: #52055. That, until now, this problem wasn't appearing was probably by chance as there was no test that actually exercised that specific flow. Here's an example of code that demonstrates the issue in current Node.js main:

const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'foo-'));
console.log('dir', dir);
const filePath = path.join(dir, 'test');
const content1 = Date.now() + 'test'.toLowerCase().repeat(1e4);
fs.writeFileSync(filePath, content1);
// In macOs the events from before calling fs.watch() may be leaked into
// the 'change' event. Uncomment the timeout to avoid it.
// setTimeout(() => {
const watcher = fs.watch(dir);
watcher.on('change', (type, filename) => {
  console.log(type, filename);
});
// }, 100);

This issue might probably be fixed once libuv/libuv#3866 is fixed, but that's not going to happen soon and definitely not for this release.
So, in order to land the incoming [email protected] my question is:

  1. Would it be acceptable to rewrite those fs.watch tests so they take into account the possible leaking of events generated before the call to fs.watch()?
  2. Or you'd prefer reverting the fix for macOS: fs.watch does not report delete of watched folder #52055 which would make the test suite pass though the underlying issue would still be there.

I'm asking this before I want to be sure Option 1 would be acceptable before rewriting all those tests, which I'm happy to pursue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.macosIssues and PRs related to the macOS platform / OSX.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions