Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sudden nwjs process exit when my native node module calls node::AtExit() #6047

Closed
semmel opened this issue Jul 21, 2017 · 4 comments
Closed

Comments

@semmel
Copy link

semmel commented Jul 21, 2017

When my add-on calls node::AtExit(myCallback, NULL); nwjs just exits suddenly:

...
The thread 0x25a4 has exited with code 3 (0x3).
The thread 0x1b28 has exited with code 3 (0x3).
The program '[10128] nwjs-sdk.exe' has exited with code 3 (0x3).

This occurs for nwjs v. 0.23.6 and 0.24-rc1 nightly. It has worked fine before (i.e. in nwjs 0.22.3).
So I assume it may be related to Node.js v.8? But that I have not verified since my dev machine still runs Node.js 0.6.9.something.

I build and run the add-on on Windows 7 Professional 32-Bit using VS Studio 2015.

The test setup is the simplest Node add-on possible:

// file hello.cc
#include "node.h"
namespace demo {
	using v8::FunctionCallbackInfo;
	using v8::Isolate;
	using v8::Local;
	using v8::Object;
	using v8::String;
	using v8::Value;

	void Method(const FunctionCallbackInfo<Value>& args) {
	  Isolate* isolate = args.GetIsolate();
	  args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
	}
	// just test if node::AtExit crashes the process
	static void onExit(void*) {
		assert(true);
	}
	void init(Local<Object> exports) {
	  NODE_SET_METHOD(exports, "hello", Method);

	  node::AtExit(onExit, NULL);  // <--- offending line, set a breakpoint here
	}
	NODE_MODULE(addon, init)
}

binding.gyp

{
  "targets": [
    {
      "target_name": "addon",
      "sources": [ "hello.cc" ]
    }
  ]
}

Building the add-on is by the book:

nw-gyp configure --target=0.23.6 --arch=ia32 --debug
nw-gyp rebuild --target=0.23.6 --arch=ia32 --debug

Next you run nw.exe (the SDK build), attach the VS Debugger to the nw.exe process (the first in the process list), and when you load the add-on from the dev console with

var addon = nw.require(String.raw`Z:\MyApp\node-modules\hello\build\Debug\addon.node`);

the debugger stops at the breakpoint. Stepping over it will then quit the whole process.

Has anyone encountered issues with node::AtExit ?

@d3x0r
Copy link

d3x0r commented Nov 12, 2017

#685

If you run with --enable-logging=stderr does it report anything more useful?

H:\dev2\nwjs\nwjs-sdk-v0.25.4-win-x64\nw.exe: e:\build\nw25_sdk_win64\node-webkit\src\third_party\node-nw\src\node.cc:4624: Assertion `(env) != (nullptr)' failed.
[20628:14360:1111/201453.346:INFO:chrome_cryptauth_service.cc(222)] Profile is not authenticated yet; waiting before starting CryptAuth managers.

is what I get... and just removing my call to node::AtExit() allows my addon to work...
I also had hooks in my loading .js script for process.on( 'exit' ) but there's only one of those, so if something else sets and on-exit that way, I don't get called.

@rogerwang
Copy link
Member

cc @Christywl

@Christywl
Copy link
Contributor

I can reproduce this issue, try on Windows 10 with Visual Studio 2015:

  1. Create hello.cc and binding.gyp files
  2. Build addon in cmd:
   nw-gyp configure --target=0.26.6 --arch=x64 --debug
   nw-gyp rebuild --target=0.26.6 --arch=x64 --debug
  1. Run nw.exe (the SDK build), attach the VS Debugger to the nw.exe process (the first in the process list)
  2. Load addon in nwjs devtools console:
var addon = nw.require(String.raw`C:\\nwjs\\bugs\\6047\\build\\Debug\\addon.node`);
  1. nwjs just exits suddenly and Output in VS:
  ...
The thread 0x27ec has exited with code 134 (0x86).
The thread 0x18f8 has exited with code 134 (0x86).
The thread 0x3b04 has exited with code 134 (0x86).
The thread 0x269c has exited with code 134 (0x86).
The thread 0x25ec has exited with code 134 (0x86).
The thread 0x3584 has exited with code 134 (0x86).
The thread 0xd4 has exited with code 134 (0x86).
The program '[11596] nw.exe' has exited with code 134 (0x86).

Step 3: Run nw.exe --enable-logging=stderr , don't see any log in cmd.

@rogerwang
Copy link
Member

This is fixed in git and will be available in the next nightly build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants