Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

persistent option ignored by fs.watch #2293

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

persistent option ignored by fs.watch #2293

eladb opened this issue Dec 8, 2011 · 8 comments
Labels

Comments

@eladb
Copy link

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
Copy link
Member

Confirmed.

@bnoordhuis
Copy link
Member

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

@aslilac
Copy link

aslilac commented Dec 8, 2011

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

@ghost
Copy link

ghost commented Dec 14, 2011

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

@TrevorBurnham
Copy link

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

@bnoordhuis
Copy link
Member

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

@bnoordhuis
Copy link
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 added a commit that referenced this issue Jan 2, 2012
Creating a file event watcher with fs.watch({persistent:false}) should not block
the event loop.
@bnoordhuis
Copy link
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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants