I'm working on a simple network proxy addon for node (yes it's sort of a crossover issue, but the error happens in ... hmm no adding run fixed that... moved the problem I guess
I cut out most of the excess code; there's still excess in the custructor callback... but I wanted to leave that flow intact. when creating a new object, I create a single uv_default_loop() that I'll never close ? on destructor I do uv_close( (uv_handle_t*)&async, NULL ); uv_run( fbdl.loop, UV_RUN_DEFAULT ); adding the run stops it from generating an assert(0) about a bad handle block in the loop (I guess, i forget the header) Assertion failed: 0, file c:\ws\deps\uv\src\win\handle-inl.h, line 159 probably this version is close https://github.com/mapbox/node/blob/master/deps/uv/src/win/handle-inl.h from a standard thread created with CreateThread in windows I call uv_async_send( &state->object->async ); I don't call uv_async_send( &state->object->async ); after the object destructs or anywhere near it... the sockets have long been closed and the object can be garbage collected because no more events will happen to it.... After running the 'uv_run' mentioend above, now node.exe is jumping to address 00000000 like somehow it lost a callback. It's a fatal crash and node just exits... ---------------------- void AppComObject::Init( Handle<Object> exports ) { // init's stuff } //--------------- Here is the callback ------- // something i'm not cleaning up here?? void asyncmsg( uv_async_t* handle ) { // Called by UV in main thread after our worker thread calls uv_async_send() // I.e. it's safe to callback to the CB we defined in node! v8::Isolate* isolate = v8::Isolate::GetCurrent(); AppComObject* myself = (AppComObject*)handle->data; HandleScope scope(isolate); { struct _MSGBUF *msg; while( msg = (struct _MSGBUF *)DequeLink( &myself->netstate->network_receive_queue ) ) { Local<Value> object = ProcessCommand( isolate, myself->netstate, msg, TRUE ); Local<Value> argv[] = { object }; Local<Function> cb = Local<Function>::New( isolate, myself->cbEvent ); cb->Call( myself->jsThis, 1, argv ); } } } AppComObject::AppComObject() { lprintf( "Create new com object %p", this ); } void AppComObject::New( const FunctionCallbackInfo<Value>& args ) { Isolate* isolate = args.GetIsolate(); if( args.IsConstructCall() ) { Handle<Function> arg0 = Handle<Function>::Cast( args[0] ); Persistent<Function> cb( isolate, arg0 ); // Invoked as constructor: `new MyObject(...)` AppComObject* obj = new AppComObject( ); obj->cbEvent = cb; if( !fbdl.loop ) // create one uv_default_loop that I keep forever??? fbdl.loop = uv_default_loop(); // had to init the async struct to 0 otherwise init din't work right? MemSet( &obj->async, 0, sizeof( obj->async ) ); uv_async_init( fbdl.loop, &obj->async, asyncmsg ); obj->async.data = obj; lprintf( "new async..." ); obj->Wrap( obj->jsThis = args.This() ); args.GetReturnValue().Set( args.This() ); } else { // Invoked as plain function `MyObject(...)`, turn into construct call. int argc = args.Length(); Local<Value> *argv = new Local<Value>[argc]; for( int n = 0; n < argc; n++ ) argv[n] = args[n]; Local<Function> cons = Local<Function>::New( isolate, constructor ); args.GetReturnValue().Set( cons->NewInstance( argc, argv ) ); delete argv; } } AppComObject::~AppComObject() { lprintf( "object evaporated. %p", this ); uv_close( (uv_handle_t*)&async, NULL ); uv_run( fbdl.loop, UV_RUN_DEFAULT ); } NODE_MODULE( app_com_module, AppComObject::Init ) -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
