diff --git a/src/node.cc b/src/node.cc index 708031740b..5ae4f0c11e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2649,6 +2649,9 @@ void StartThread(node::Isolate* isolate, if (isolate->id_ > 1) { process_l->Set(String::NewSymbol("_send"), FunctionTemplate::New(Isolate::Send)->GetFunction()); + + process_l->Set(String::NewSymbol("_exit"), + FunctionTemplate::New(Isolate::Unref)->GetFunction()); } // FIXME crashes with "CHECK(heap->isolate() == Isolate::Current()) failed" diff --git a/src/node.js b/src/node.js index 1be049027b..4d382af95f 100644 --- a/src/node.js +++ b/src/node.js @@ -135,6 +135,8 @@ msg = JSON.parse('' + msg); process.emit('message', msg); }; + + process.exit = process._exit; } startup.globalVariables = function() { diff --git a/src/node_isolate.cc b/src/node_isolate.cc index 52cf0903a5..a0d2c4507e 100644 --- a/src/node_isolate.cc +++ b/src/node_isolate.cc @@ -215,6 +215,16 @@ Handle Isolate::Send(const Arguments& args) { } +Handle Isolate::Unref(const Arguments& args) { + HandleScope scope; + + Isolate* isolate = Isolate::GetCurrent(); + uv_unref(isolate->loop_); + + return Undefined(); +} + + void Isolate::OnMessage(IsolateMessage* msg, void* arg) { HandleScope scope; @@ -270,6 +280,11 @@ Isolate::Isolate() { assert(v8_isolate_->GetData() == NULL); v8_isolate_->SetData(this); + // Artificially ref the isolate loop so that the child + // isolate stays alive by default. process.exit will + // unref the loop (see Isolate::Unref). + uv_ref(loop_); + globals_init_ = false; } diff --git a/src/node_isolate.h b/src/node_isolate.h index b08ecf3912..12e5921a5b 100644 --- a/src/node_isolate.h +++ b/src/node_isolate.h @@ -74,6 +74,7 @@ public: typedef void (*AtExitCallback)(void* arg); static v8::Handle Send(const v8::Arguments& args); + static v8::Handle Unref(const v8::Arguments& args); static Isolate* GetCurrent() { return reinterpret_cast(v8::Isolate::GetCurrent()->GetData()); diff --git a/test/simple/test-isolates0.js b/test/simple/test-isolates0.js index d06628f70b..b85fc63023 100644 --- a/test/simple/test-isolates0.js +++ b/test/simple/test-isolates0.js @@ -52,6 +52,7 @@ if (process.tid === 1) { fs.stat(__dirname, function(err, stat) { if (err) throw err; console.error('thread 2', stat.mtime); + process.exit(); }); }, 500);