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

Package sometimes causes segfaults on Node v14 #19

Open
davidmurdoch opened this issue Oct 7, 2020 · 3 comments
Open

Package sometimes causes segfaults on Node v14 #19

davidmurdoch opened this issue Oct 7, 2020 · 3 comments

Comments

@davidmurdoch
Copy link

I'm sorry my reproduction steps are so horrible... but I just haven't been able to figure out how to reliably trigger the error.

To reproduce:

  1. git clone https://github.com/trufflesuite/ganache-core.git
  2. cd ganache-core
  3. git checkout 8a4fb09c970d2ded061c1b1e1fd912cd7ae0229a
  4. nvm use 14
  5. npm ci
  6. npm test (you may have to run this many times until you trigger the segfault)

You should see something like:

Segmentation fault (core dumped)
npm ERR! code 139
npm ERR! path /home/david/work/ganache-core
npm ERR! command failed
npm ERR! command sh -c mocha --check-leaks --recursive "./test/local"

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/david/.npm/_logs/2020-10-07T15_21_43_948Z-debug.log

(The debug log isn't helpful)

I've somewhat "fixed" this in ganache-core by patching keccak so it never loads the native modules.

To reproduce my workaround:

  1. git checkout c26ba24ebf24d1c09b328a76baf0cf43e82fba04
  2. npm ci (if you are using npm 7.0.0-rc.0 you'll need to also run npm run postinstall)
  3. npm test (run it as many times as you'd like; it doesn't crash anymore... I ran the tests for over an hour via while npm test; do :; done without a crash)

Here is the patch, if you're curious: https://github.com/trufflesuite/ganache-core/blob/c26ba24ebf24d1c09b328a76baf0cf43e82fba04/patches/keccak%2B3.0.1.patch#L1-L11

The biggest issue with my workaround is that patch-package isn't safe to use in published npm modules. :-(

I've also opened this issue in ethereum-cryptography because I figured it might be faster/easier to update that package to do something like const keccak = require("keccack/js"); (untested) than it would be to figure out the fix in this package's native code.

Note: removing nyc from the test command reduces the likelihood of the crash, however, it does still occur when running with mocha only.

@fanatid
Copy link
Member

fanatid commented Oct 8, 2020

😞

Is there a way to get a simpler code for reproducing error? Maybe a specified function call with specified data?

@davidmurdoch
Copy link
Author

I can't narrow it down further right now, as I've got some other important issues to work on (updating ganache-core to work with Node v14 has taken me well over a week now!). I haven't been able to find a minimal reproduction, as when I reduce complexity the the segfault error becomes less likely to occur.

The thought has occurred to me that it is possible keccak isn't even the problem; another native package may be misbehaving by attempting to read/write memory, and having keccak native loaded simply triggers a bug in the other native library -- something that causes its own internal memory references to be misaddressed/aligned 😅

I think right now, the best we can hope for is that others run into the same problem and find this issue and comment below :-).

I've found a temporary workaround in ganache (bundling keccak into ganache-core without the native modules), so it's not a super high priority for ganache-core specifically.

Here are some reproductions of the issue on Travis CI:

Node.js: 14.13.0 Ubuntu 16.04: https://travis-ci.org/github/trufflesuite/ganache-core/jobs/733700191#L1324

Node.js: 14.13.0 OS X 10.12.6: https://travis-ci.org/github/trufflesuite/ganache-core/jobs/733700194#L1101

@davidmurdoch
Copy link
Author

Oh wait... I just found this failure on Node v10 on OS X 10.12.6!

https://travis-ci.org/github/trufflesuite/ganache-core/jobs/733700192#L1149

Hmmmm, this is the first I've noticed it on anything but Node 14. Not sure what to make of this discovery...

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

2 participants