persistent option ignored by fs.watch #2293

Closed
eladb opened this Issue Dec 8, 2011 · 8 comments

Projects

None yet

4 participants

@eladb
eladb commented Dec 8, 2011

fs.watch seem to be broken on mac.
This script (named j.js) does not exit.

var fs = require('fs');
fs.watch('j.js', { persistent: false }, function() {
    console.log('changed');
});

P.S. fs.watchFile is working.

@bnoordhuis
Member

Confirmed.

@bnoordhuis
Member

What is? {persistent:false} should work but doesn't.

@partheseas

Sorry. I didn't notice the persistent false somehow.

@ghost
ghost commented Dec 14, 2011

I have this error as well on my Mac. It doesn't respond to a change.

@TrevorBurnham

Could someone please change the issue title to something more specific, like "persistent option ignored by fs.watch under OS X"?

@bnoordhuis
Member

Updated. It's not specific to OS X, by the way.

@bnoordhuis
Member

This bug is a manifestation of a design flaw in the UNIX part of libuv. It's quite fixable, we just need to decide on the best approach.

The event loop maintains a reference count of active handles. Setting {persistent:false} makes Node drop the reference count by one but it turns out that some handle types - including uv_fs_event_t - are counted twice, hence the event loop remains alive.

@bnoordhuis bnoordhuis added a commit that referenced this issue Jan 2, 2012
@bnoordhuis bnoordhuis test: add #2293 regression test
Creating a file event watcher with fs.watch({persistent:false}) should not block
the event loop.
884f689
@bnoordhuis
Member

Fixed in joyent/libuv@38fc6ad. The libuv that's bundled with node has been upgraded in 41f2725, a regression test has been added in 884f689.

@bnoordhuis bnoordhuis closed this Jan 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment