Skip to content

change in behavior of fs.watch between node 10.15.3 and 10.16 #28512

Description

@daprahamian
  • Version: v10.16.0
  • Platform: Darwin Dans-MacBook-Pro-4.local 16.7.0 Darwin Kernel Version 16.7.0: Wed Feb 27 00:29:57 PST 2019; root:xnu-3789.73.43~1/RELEASE_X86_64 x86_64
  • Subsystem: fs

Code to reproduce:

const assert = require('assert');
const { createWriteStream, watch, readFileSync } = require('fs');

const doc = '{ "a": 1 }';
const filename = '/tmp/reproducer.txt';
const outStream = createWriteStream(filename);

setTimeout(() => outStream.write(doc), 2000);

const watcher = watch(filename, function(eventType) {
  assert.equal(eventType, 'change');

  var fileContents = readFileSync(filename, 'utf8');
  try {
    var parsedFileContents = JSON.parse(fileContents);
    assert.equal(parsedFileContents.a, 1);
    console.log('success');
  } catch (e) {
    console.log(e);
    console.log(`JSON contents: \`${fileContents}\``);
  } finally {
    watcher.close();
    console.log('done');
  }
});

Output in node v10.15.3:

success
done

Output in node v10.16.0:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at FSWatcher.<anonymous> (/Users/daprahamian/src/node-mongodb-native/repro.js:17:35)
    at FSWatcher.emit (events.js:198:13)
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:131:12)
JSON contents: ``
done

Is this an intentional change, or a regression?

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.macosIssues and PRs related to the macOS platform / OSX.

    Type

    No type

    Fields

    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