Skip to content

fs.watch incorrect event behavior on directories with rapid create/delete operations (Windows/Linux) #60859

@sharvandeep

Description

@sharvandeep

Summary

When using fs.watch on a directory with rapid file creation and deletion events, the callback sometimes receives incorrect event types or misses events entirely. Behavior differs across OS platforms (Windows/Linux).

Steps to Reproduce

  1. Create a script that uses fs.watch on a test directory.
  2. Rapidly create/delete files in that directory (e.g., using a loop or CLI tool).
  3. Observe that:
    • Some rename events are not emitted.
    • change events are emitted unexpectedly.
    • In rare cases, no events occur until another file operation triggers them.

Expected Behavior

fs.watch should emit event callbacks consistently for every create/delete operation.

Actual Behavior

Events are missed or reported incorrectly, especially under high-frequency changes.

Environment

  • Node.js version: Latest Stable (please fill exact if required)
  • OS: Windows 11 / Ubuntu 22.04 (issue observed on both)
  • Reproduction code:
const fs = require('fs');
fs.watch('./test', (event, file) => {
  console.log(event, file);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions