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

Async/Await crash: assertion env->async_hooks_init_function().IsEmpty() failed #10905

Closed
drcmda opened this issue Oct 25, 2017 · 29 comments
Closed

Comments

@drcmda
Copy link

drcmda commented Oct 25, 2017

  • Electron version: Anything over 1.7.8, until the latest 1.8.2-beta.1
  • Node: 8.8.0
  • Operating system: high sierra

Going over 1.7.8 seems to break Electron for one of our projects. It's hard to track down what's going on but here's the output:

❯ yarn run electron
yarn run v1.2.1
$ electron .dev/electron.js
/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron[41928]: ../../vendor/node/src/async-wrap.cc:399:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: node::Abort() [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 2: node::Assert(char const* const (*) [4]) [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 3: node::AsyncWrap::Initialize(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>) [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 4: v8::internal::StrDup(char const*) [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 5: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 6: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/Users/drcmda/dev/stepdoctor/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 7: 0x3eadf51843fd
 8: 0x3eadf527777c
 9: 0x3eadf523be1c
✨  Done in 0.40s.

It happens when we require a file that has async/await calls in it, but nothing's yet executed. But the moment we go back to 1.7.8 it starts working again.

@felixrieseberg
Copy link
Member

Are you able to provide a repro? It would really help us track this down!

@felixrieseberg felixrieseberg added component/node-integration blocked/need-info ❌ Cannot proceed without more information labels Oct 25, 2017
@drcmda
Copy link
Author

drcmda commented Oct 26, 2017

@felixrieseberg

npm install awv3-node

and somewhere in electron.js (the startup file, for instance in the electron-quick-start):

const Server = require('awv3-node/server')

That's enough to shoot it down. No code is actually executed, it just fetches the class which happens to have some async/await stuff in it.

@thdtjsdn
Copy link

thdtjsdn commented Oct 27, 2017

I have the same symptoms.

1.7.8 - No problems.
1.7.9 - I have not tested it.

1.8.1 beta - same error
1.8.2 beta.1 - same error

E:\GitHub_B2LiNK\Development-Binary-Windows\Binary\Electron\electron.exe: c:\projects\electron\vendor\node\src\async-wrap.cc:399: Assertion `env->async_hooks_init_function().IsEmpty()' failed.

require( "exceljs" ) -> error

It happens on Windows, Mac, and Linux.

@wolovim
Copy link

wolovim commented Nov 17, 2017

Any workarounds or useful leads discovered yet? Same issue here, with or without babel in the stack.

@gozzoo
Copy link

gozzoo commented Nov 28, 2017

It happens on Windows 7 too.

@remss
Copy link

remss commented Dec 6, 2017

Same error on 1.8.2 beta.3

@bengotow
Copy link
Contributor

I'm getting this in Mailspring when running anything newer than 1.7.8. Unfortunately I'm really not sure how to track it down because the stack trace doesn't reference any specific JS code or file.

@bengotow
Copy link
Contributor

bengotow commented Dec 22, 2017

Ok folks - I've made some headway here. Using an empty Electron project, I'm able to reproduce this by requiring awv3-node/server as noted above. To find exactly what source is crashing Node, I:

  1. Launched the test Electron project, and attached lldb to the renderer process.
  2. Open the Chrome Devtools and navigate to module.js and add a console.log to Module._load logging the filename it's about to load.
  3. Make the app call require('awv3-node/server'). The devtools logs a bunch of paths and then hits the assertion failure in the stack trace, but LLDB prevents it from exiting so I can read the console.logs.

The file crashing the app is /Users/bengotow/Work/F376/Projects/Podtastic/node_modules/natives/index.js. It looks like it's doing some /hella/ sketchy stuff. In the package description, it basically says it's can and will break your app when Node changes: https://www.npmjs.com/package/natives. Lovely.

Rather than figure out what in this (actually very small) package has broken, I think the goal should be to remove it and whatever dependencies are doing such sketch stuff in the first place. In the case of awv3-node, here's the full require path to natives (reading down roughly):

ode_modules/awv3-node/server.js
node_modules/unzip/unzip.js
node_modules/unzip/lib/parse.js
node_modules/setimmediate/setImmediate.js
node_modules/readable-stream/transform.js
node_modules/readable-stream/lib/_stream_transform.js
node_modules/readable-stream/lib/_stream_duplex.js
node_modules/core-util-is/lib/util.js
node_modules/readable-stream/lib/_stream_readable.js
node_modules/readable-stream/node_modules/isarray/index.js
node_modules/readable-stream/lib/_stream_writable.js
node_modules/binary/index.js
node_modules/chainsaw/index.js
node_modules/traverse/index.js
node_modules/buffers/index.js
node_modules/binary/lib/vars.js
node_modules/pullstream/pullstream.js
node_modules/readable-stream/passthrough.js
node_modules/readable-stream/lib/_stream_passthrough.js
node_modules/over/overload.js
node_modules/slice-stream/slicestream.js
node_modules/match-stream/match.js
node_modules/unzip/lib/entry.js
node_modules/unzip/lib/extract.js
node_modules/unzip/node_modules/fstream/fstream.js
node_modules/unzip/node_modules/fstream/lib/abstract.js
node_modules/unzip/node_modules/fstream/lib/reader.js
node_modules/unzip/node_modules/graceful-fs/graceful-fs.js
node_modules/unzip/node_modules/graceful-fs/fs.js
node_modules/natives/index.js

Stepping through the execution of https://github.com/isaacs/natives/blob/master/index.js, (I just edited the source on disk and added a debugger line), it looks like it calls runInThisContext on sources within NodeJS itself. When it calls runInThisContext with nm.filename = async_hooks.js, it retrieves the function, but when it executes it on line 109, the assertion failure occurs and Node crashes.

@xialvjun
Copy link

update exceljs 's graceful-fslike this issue ?

@drcmda
Copy link
Author

drcmda commented Feb 2, 2018

@bengotow Thanks for investigating! I wasn't aware of "natives", but we do use fs-extra, which loads graceful-fs. So looks like they have removed it.

@kewde
Copy link
Contributor

kewde commented Feb 7, 2018

We're having the same issue with 1.8.2.

Linux, debian.

/home/user/projects/particl/partgui/node_modules/electron/dist/electron[1930]: ../../vendor/node/src/async-wrap.cc:399:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: node::Abort() [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 2: 0x78c63c361e84 [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 3: 0x78c63c3519d5 [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 4: 0x78c63bea2550 [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 5: 0x78c63bd10d98 [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 6: 0x78c63bd1030e [/home/user/projects/particl/partgui/node_modules/electron/dist/libnode.so]
 7: 0x8a9ebf843fd

@kewde
Copy link
Contributor

kewde commented Feb 7, 2018

This issue deserves a red "crash" label.

@swampthang
Copy link

swampthang commented Feb 18, 2018

Any progress on this? I am having the same issue. I use leveldown - requiring a native module rebuild - and I'm in a bit of a catch-22. Node.js 7.10.1 uses NODE_MODULE_VERSION 51 and the next one up, Node.js 8.0.0 uses NODE_MODULE_VERSION 57. Electron version 1.7.x uses 54 but 1.8.x breaks the app.

@paperscissors
Copy link

running into the same issue on 1.8.x on macOS 10.12, node v8.9.4.

@framerate
Copy link

framerate commented Feb 26, 2018

D:\code\MyProject\node_modules\electron\dist\electron.exe: c:\projects\electron\vendor\node\src\async-wrap.cc:399: Assertion `env->async_hooks_init_function().IsEmpty()' failed

On windows.

EDIT: Roll back to 1.7.12 and seems ok.

@joefiorini
Copy link

I am also seeing this issue on the latest electron using electron mocha. I have a repo that reproduces it (run yarn followed by yarn test to reproduce). I can verify that like @framerate if I rollback on 1.7.12 it works fine.

@maa105
Copy link

maa105 commented Mar 6, 2018

node 8.2.1 electron 1.8.3
Same issue @bengotow is correct I followed through it. it crashes when requiring natives then when nm.filename = "async_hooks.js" if you follow through more however it crashes inside "async_hooks.js" line 60

  // Setup the callbacks that node::AsyncWrap will call when there are hooks to
  // process. They use the same functions as the JS embedder API. These callbacks
  // are setup immediately to prevent async_wrap.setupHooks() from being hijacked
  // and the cost of doing so is negligible.
  async_wrap.setupHooks({ init: emitInitNative,
                        before: emitBeforeNative,
                        after: emitAfterNative,
                        destroy: emitDestroyNative });

async_wrap.setupHooks is a native function it seems and I cannot step into it. and right after I press f11 on this line of code the electron app crashes and I get "DevTools was disconnected from the page."

for me I got this error requiring gulp but following through the tree of dependencies I narroed it down to fs module so I replaced the require('gulp') with a require('fs') to test it and indeed require('fs') is enough to break the app in the same line of code.

So in short 'fs' is the culprit it seems from what I gather

any help is greatly appriciated

@kickthedragon
Copy link

kickthedragon commented Mar 7, 2018

Getting a very similar error here on Mac OS high sierra just from importing the unzip package into my project.

electron v1.8.2

unzip = require('unzip');


node_modules/electron/dist/Electron.app/Contents/MacOS/Electron[5397]: ../../vendor/node/src/async-wrap.cc:399:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: node::Abort() [/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 2: node::Assert(char const* const (*) [4]) [/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 3: node::AsyncWrap::Initialize(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>) [/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 4: v8::internal::StrDup(char const*) /node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 5: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 6: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/Users/kickthedragon/Projects/launcher-patcher/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 7: 0xca6c5043fd

@krimeshu
Copy link

The same problem, both Windows and Mac OS.

@bpasero
Copy link
Contributor

bpasero commented Apr 6, 2018

VS Code is hitting the same problem for users that have the live share extension installed (https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare). My understanding is that some old dependency can trigger this but to be honest a native crash should never occur from a JS execution so I think this must be fixed in node.js or electron to prevent from happening?

@bpasero
Copy link
Contributor

bpasero commented Apr 6, 2018

Steps to reproduce:

package.json:

{
    "name": "name",
    "description": "description",
    "authors": "author",
    "version": "1.0.0",
    "main": "pathToMain",
    "dependencies": {
        "fstream": "0.1.31"
    }
}

index.js

var fstream = require("fstream");

console.log(fstream);

From the command line: ./Electron index.js

Output:

/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron[58474]: ../../vendor/node/src/async-wrap.cc:357:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: node::Abort() [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 2: node::Assert(char const* const (*) [4]) [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 3: node::AsyncWrap::Initialize(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Context>) [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 4: v8::internal::StrDup(char const*) [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 5: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 6: v8::internal::compiler::BranchElimination::ControlPathConditions::operator==(v8::internal::compiler::BranchElimination::ControlPathConditions const&) const [/Users/bpasero/Desktop/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib]
 7: 0x283bd930463d
Abort trap: 6

I cannot reproduce this with node.js 8.9.3 so I think this is something Electron has to fix.

@bpasero
Copy link
Contributor

bpasero commented Apr 6, 2018

As @MarshallOfSound found out, this actually can reproduce also in node.js by code such as:

require('natives').require('child_process')

So now I am actually less sure about wether this should be fixed in Electron or if this should be forwarded to node.js team :-/

@tehnorm
Copy link

tehnorm commented Apr 6, 2018

As a point of clarification, in our experience the root cause of this issue is something that was depending on the natives package.

This package is deprecated and contains warnings of its use. Right from the natives README:

Caveat
Dear Beloved User,

I feel compelled to give you a word of warning if you are considering using this module.

This module lets you do some creative things with the JavaScript code in Node.js. There are some > things here that are basically a recipe for memory leaks, or at the very least, being broken with
each new release of Node, since none of these API surfaces are "technically" "supported" by the > > team managing the Node.js project.

So. Doesn't seem to be electron's issue. Heck, this isn't even a node issue. Packages depending on the natives module, which is now deprecated and one could even argue - not be used in the first place are the issue.

Note: gulp v3.9.1 has this issue. The solution for us was to upgrade to gulp 4.

@bpasero
Copy link
Contributor

bpasero commented Apr 9, 2018

I am thinking this should be fixed in node.js. No normal JS code execution should trigger a native crash that cannot be handled. For that reason there are runtime exceptions in JS that can be used.

@bpasero
Copy link
Contributor

bpasero commented Apr 10, 2018

As a workaround (thanks to @Tyriar) we will probably ship with this code to prevent access to the natives module which seems to be the main driver of this crash:

(function () {
	const Module = require('module');
	const originalLoad = Module._load;

	Module._load = function (request) {
		if (request === 'natives') {
			throw new Error('bad');
		}

		return originalLoad.apply(this, arguments);
	};
})();

@kikill95
Copy link

kikill95 commented Apr 20, 2018

I have this error with electron v. 2.0.0-beta.7 and beta.8 - works fine on macos and bad on windows

@sofianguy sofianguy added the blocked/upstream ❌ Blocked on upstream; e.g. Chromium or Node label Apr 20, 2018
@kikill95
Copy link

kikill95 commented May 1, 2018

Hello, everyone, I have found that the problem was really inside native module. For me, I've changed Unzip2 package with unzipper package and this started to work. Also, I had gulp 3.9.1. I used this in electron@2.0.0-beta.8. It was really hard to find where is the problem, because my app used module that used another module that used this Unzip2.

Maybe this will help someone, but a lot of things and work with xls/xlsx files are related to this unzip2 module. In my case I just changed unzip2 with unzipper and this started to work!

Alhadis added a commit to file-icons/atom that referenced this issue Aug 9, 2018
The latter is the same problem described by electron/electron#10905; the
solution @kikill95 suggested of replacing `unzip` with `unzipped` worked
great.
@jarrodek
Copy link

I have this issue when trying to use https://www.npmjs.com/package/unzip library:

/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/electron[26122]: ../../vendor/node/src/async-wrap.cc:357:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: node::Abort() [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 2: 0x7f5a12249cf4 [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 3: 0x7f5a12234025 [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 4: 0x7f5a11b2ebba [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 5: 0x7f5a11a22662 [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 6: 0x7f5a11a21d74 [/home/pawel/workspace/advanced-rest-client/arc-electron/node_modules/electron/dist/libnode.so]
 7: 0x1ee39ad0463d

@codebytere
Copy link
Member

Closing as the root of this issue is not clearly with Electron itself.

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