nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node
34.41k stars 7.31k forks source link

Multiple fs.watch on one file = Segmentation fault #3789

Closed haraldrudell closed 12 years ago

haraldrudell commented 12 years ago

SYMPTOM: Two watchers on the same file = Segmentation fault

I have an app that does this. It either segfaults or only notifies one of the watchers. My life is miserable.

setTimeout seems to have similar challenges.

REPRO: foxyboy@c505:~/Desktop/c505/node/nodejs3$ node snippets/nodeapi/nodeapi-fswatch.js watchFunc1 watchFunc1 Segmentation fault (core dumped)

uname -a; node -v Linux c505 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux v0.8.4

CODE:

// nodeapi-fswatch.js

// http://nodejs.org/docs/latest/api/fs.html
var fs = require('fs')
// http://nodejs.org/api/path.html
var path = require('path')

var file = path.join(__dirname, 'data', 'text.txt')

var w1 = fs.watch(file, watchFunc1)
var w2 = fs.watch(file, watchFunc2)

fs.writeFileSync(file, 'text')
setTimeout(f, 200)

function watchFunc1() {
    console.log(arguments.callee.name)
}
function watchFunc2() {
    console.log(arguments.callee.name)
}

function f() {
    w1.close()
    w2.close()
}
bnoordhuis commented 12 years ago

Thanks for the bug report. Fixed in 879d329.

haraldrudell commented 12 years ago

it worx!

thanks for i can haz fiks