joyent/node — Issue #2813: OS X: test/simple/test-fs-watch.js hangs
Author: isaacs
Created: 2012-02-23 04:13:22+00:00
State: open

This minimal test hangs, as well:

```javascript
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var filepath = path.join(common.tmpDir, 'watch.txt');

try { fs.unlinkSync(filepath); } catch (e) { }
fs.writeFileSync(filepath, 'hello');

var watcher = fs.watch(filepath, function(event, filename) {
console.error('got event');
assert.equal('change', event);
watcher.close();
});

setTimeout(function() {
fs.writeFileSync(filepath, 'world');
}, 500);
```

Interestingly, if you replace the `fs.writeFileSync(filepath, 'world');` with `watcher.close()` then it releases and closes gracefully. But if it ever gets a change event, then it becomes impossible to close.