Browse files

Prevent abort trap on exit

When running a debug version of v8 and your application terminates while
there are still yielding fibers there's an abort trap that gets caught
and a scary error message. v8 is trying to cleanup resources while is getting unloaded and it's all-around bad news. This
quick and dirty hack prevents v8 from cleaning up, which actually
doesn't make a huge difference since the application is terminating
  • Loading branch information...
1 parent 041247c commit 82f79cea93c98d439b959e8778fe58c1e9310548 @laverdet committed Jan 22, 2011
Showing with 8 additions and 2 deletions.
  1. +8 −2
@@ -21,7 +21,7 @@ class Fiber {
target = *static_cast<Fiber*>(handle->GetPointerFromInternalField(0));
- static Locker locker; // Node does not use locks or threads, so we need a global lock
+ static Locker* locker; // Node does not use locks or threads, so we need a global lock
static Persistent<FunctionTemplate> tmpl;
static Fiber* current;
static vector<Fiber*> orphaned_fibers;
@@ -442,6 +442,12 @@ class Fiber {
* Initialize the Fiber library.
static void Init(Handle<Object> target) {
+ // Use a locker which won't get destroyed when this library gets unloaded. This is a hack
+ // to prevent v8 from trying to clean up this "thread" while the whole application is
+ // shutting down. TODO: There's likely a better way to accomplish this, but since the
+ // application is going down lost memory isn't the end of the world. But with a regular lock
+ // there's seg faults when node shuts down.
+ Fiber::locker = new Locker;
HandleScope scope;
tmpl = Persistent<FunctionTemplate>::New(FunctionTemplate::New(New));
@@ -463,7 +469,7 @@ class Fiber {
Persistent<FunctionTemplate> Fiber::tmpl;
-Locker Fiber::locker;
+Locker* Fiber::locker;
Fiber* Fiber::current = NULL;
vector<Fiber*> Fiber::orphaned_fibers;
Persistent<Value> Fiber::fatal_stack;

0 comments on commit 82f79ce

Please sign in to comment.