Skip to content

Node 20 recursive file watching is misbehaving on Linux #48437

@cjihrig

Description

@cjihrig

Version

20.3.0

Platform

linux

Subsystem

fs

What steps will reproduce the bug?

I put together a repro at https://github.com/cjihrig/recursive-watcher-bug that shows the following passing on Windows and macOS, but failing on Ubuntu. I'm not sure if this is specific to GitHub Actions.

'use strict';
const { mkdtempSync, watch, writeFileSync } = require('node:fs');
const { tmpdir } = require('node:os');
const { join } = require('node:path');
const tmpDir = mkdtempSync(join(tmpdir(), 'repro-test-'));
const filename = join(tmpDir, 'test.file');
const keepalive = setTimeout(() => {
  throw new Error('timed out');
}, 60_000);

const watcher = watch(tmpDir, { recursive: true }, (eventType, filename) => {
  clearTimeout(keepalive);
  watcher.close();
  console.log(eventType, filename);
});

writeFileSync(filename, 'foobar');

How often does it reproduce? Is there a required condition?

Always reproduces for me.

What is the expected behavior? Why is that the expected behavior?

I expect the test to pass.

What do you see instead?

The test times out.

Additional information

I noticed this while trying to update Platformatic to support Node 20 and created the minimal reproduction linked above.

I also noticed that Platformatic was passing recursive: true to the promisified version of watch() on Ubuntu on earlier versions of Node. It should have thrown ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, but did not. I did see that error with the callback based watch() though, which makes me think there is some missing validation on older versions of Node in addition to this bug.

cc: @anonrig who implemented recursive file watching on Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.fsIssues and PRs related to the fs subsystem / file system.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions