Skip to content

fs.watch() listener called with null filename argument #61520

@lpinca

Description

@lpinca

Version

main (commit 159ae48)

Platform

SunOS smartos 5.11 joyent_20260122T000642Z i86pc i386 i86pc

Subsystem

fs

What steps will reproduce the bug?

const fs = require('fs');

const watcher = fs.watch('.', {
  recursive: false // The test passes if this option is set to `true`.
});

watcher.on('change', function (event, filename) {
  console.log(event, filename);

  if (filename === 'file.txt') {
    watcher.close();
  }
});

setTimeout(function () {
  fs.writeFileSync('file.txt', 'data');
}, 100);

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

Always.

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

change file.txt is written to the standard output and the process exits. This is what happens when the recursive option is set to true.

What do you see instead?

change null is written to the standard output and the process does not exit.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    freebsdIssues and PRs related to the FreeBSD platform.fsIssues and PRs related to the fs subsystem / file system.smartosIssues and PRs related to the SmartOS platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions