question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash in forked child process when calling node method runInNewContext.

See original GitHub issue

NWJS Version : 0.29.4 - 0.39.1 Operating System : Linux, Windows 10

Expected behavior

Process created by child_process.fork('./src/child.js', { stdio: 'pipe' }) should not crash when calling runInNewContext

Actual behavior

When calling runInNewContext in a process created by child_process.fork('./src/child.js', { stdio: 'pipe' }) The child process crashes with: FATAL ERROR: v8::Context::SetAlignedPointerInEmbedderData() Pointer is not aligned

How to reproduce

Create a child process with: child_process.fork('./src/child.js', { stdio: 'pipe' }) In the childprocess run this code:

  const { runInNewContext } = require('vm');
  getStructuredStack = runInNewContext(`(function() {
      Error.prepareStackTrace = function(err, trace) {
      err.stack = trace;
      };
      Error.stackTraceLimit = Infinity;
      return function structuredStack() {
      return new Error().stack;
      };
  })()`, {}, { filename: 'structured-stack' });

  const stack = getStructuredStack();

To test this i have made a small test project: nwjs-crash-test01.zip Unzip it and run: npm install

Linux

To run with NW.js: ./node_modules/nw-builder/bin/nwbuild -r . To run with node: node src/main.js

Windows

To run with NW.js: node .\node_modules\nw-builder\bin\nwbuild -r . To run with node: node .\src\main.js

The test program will run the same 4 test with NW.js or node

  1. In parent process call a node method, to verify that node is working.
  2. In parent process call runInNewContext
  3. In child process call runInNewContext
  4. In child process call const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])

The last test is because that is actually the blocking problem i have, When calling a deprecated method in node buffer it will eventual call runInNewContext and crash.

When running the NW.js version of the test it will open the developer tool and print the faulr output from the child process to the console. To run all 4 test cases press the “run code” button 6 times.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwangcommented, Jun 26, 2019

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

0reactions
rogerwangcommented, Jun 27, 2019

sure

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Problem with forked child process is killing parent ...
I have a child process which loops through colors to grab a palette. It works fine with smaller images, but when I upload...
Read more >
NW.js v0.39.2 Released with Node.js 12.4.0 and Chromium ...
Update Chromium to 75.0.3770.100; Update Node.js to v12.4.0; Fix: Crash in forked child process when calling node method runInNewContext.
Read more >
Node.js ChangeLog
Lots of bug fixes, including: Memory leak in ChildProcess:Spawn(). (Tom Hughes); buffer.slice(0, 0); Global variable leaks; clearTimeouts calling multiple times ...
Read more >
Node.js v4.2.6 Documentation
Use the spawn() , exec() , execFile() , or fork() methods to create an instance of ChildProcess . Event: 'close'#. code Number the...
Read more >
Node.js ChangeLog - Google Git
Surrogate pair in REPL can freeze terminal. #690; Calling dns.setServers() while a DNS query is in progress can cause the process to crash...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found