Closed
Description
- Version: v10.0.0
- Platform: windows 10 (x64) & linux 4.13.0-38-generic (x86_64)
- Subsystem: fs
Calling close()
from fs.watch
may crash node process.
From my test:
- on Windows 10 will crash every time
- on Linux may crash 20% of the time
The minimal reproducible code: (will not crash on node 8 or 9)
const { watch, mkdirSync, rmdirSync, existsSync } = require('fs')
const { join } = require('path')
const TEST_ROOT = join(__dirname, 'test-watch-gitignore/')
existsSync(TEST_ROOT) || mkdirSync(TEST_ROOT)
const watcher = watch(TEST_ROOT, { persistent: false, recursive: false })
watcher.addListener('error', () => { // TODO: NOTE: crash on windows node 10, every time
console.log('error ===============')
setTimeout(() => { // TODO: NOTE: remove this will stop the crash
console.log('error setTimeout ===============')
watcher.close()
console.log('error done ===============')
}, 10)
})
watcher.addListener('change', () => { // TODO: NOTE: crash on linux node 10, 20% of the time
console.log('change ===============')
setTimeout(() => { // TODO: NOTE: remove this will stop the crash
console.log('change setTimeout ===============')
watcher.close()
console.log('change done ===============')
}, 10)
})
console.log('111 ===============')
rmdirSync(TEST_ROOT)
console.log('222 ===============')
setTimeout(() => {}, 100) // TODO: NOTE: wait for listener to hit
console.log('333 ===============')
The error on Windows:
> node .\test-bug.js
111 ===============
222 ===============
333 ===============
error ===============
error setTimeout ===============
Windows PowerShell[22248]: src\fs_event_wrap.cc:90: Assertion `wrap != nullptr' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: node::Start
4: v8::internal::interpreter::BytecodeDecoder::Decode
5: v8::internal::RegExpImpl::Exec
6: v8::internal::RegExpImpl::Exec
7: v8::internal::Object::ToInt32
8: v8::internal::Object::GetProperty
9: v8::internal::NativesCollection<0>::GetScriptsSource
10: v8::internal::NativesCollection<0>::GetScriptsSource
11: 00000383BE284281
The error on Linux:
$ node test-bug.js
111 ===============
222 ===============
333 ===============
change ===============
change ===============
change setTimeout ===============
change done ===============
change setTimeout ===============
node[14950]: ../src/fs_event_wrap.cc:90:static void node::{anonymous}::FSEventWrap::GetInitialized(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `wrap != nullptr' failed.
1: node::Abort() [node]
2: 0x87b6c5 [node]
3: 0x86a60a [node]
4: v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo*) [node]
5: 0xad62fa [node]
6: v8::internal::Builtins::InvokeApiFunction(v8::internal::Isolate*, bool, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*, v8::internal::Handle<v8::internal::HeapObject>) [node]
7: v8::internal::Object::GetPropertyWithAccessor(v8::internal::LookupIterator*) [node]
8: v8::internal::Object::GetProperty(v8::internal::LookupIterator*) [node]
9: v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [node]
10: v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
11: 0x12b965e0427d
Aborted (core dumped)