Bug 393415 - Valgrind memory debugging for nodejs using child process failed on MacOS
Summary: Valgrind memory debugging for nodejs using child process failed on MacOS
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.14 SVN
Platform: Compiled Sources macOS
: NOR normal
Target Milestone: ---
Assignee: Rhys Kidd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-23 09:12 UTC by Nazar Hussain
Modified: 2021-01-03 16:10 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nazar Hussain 2018-04-23 09:12:29 UTC
I am trying to debug a nodejs script which has dependencies on native bindings. That script also involves forking a child process. I am using valgrind to debug the memory issues with following options:

```
valgrind --leak-check=summary --show-leak-kinds=all --trace-children=yes --verbose  node app.js
```

It only works if I set `--trace-children=no`, otherwise always failed.

I created following sample script to test the scenario and it seems valgrind does not work debugging child process running in node.


```
// main.js
var cp = require('child_process');
var child = cp.fork('./worker');

child.on('message', function(m) {
  // Receive results from child process
  console.log('received: ' + m);
});

// Send child process some work
child.send('Please up-case this string');
```

and 

```
worker.js
process.on('message', function(m) {
  // Do work  (in this case just up-case the string
  m = m.toUpperCase();

  // Pass results back to parent process
  process.send(m.toUpperCase(m));
});
```


And `valgrind` always failed with following error:

```
==10401== execve(0x1048a3150(/bin/bash), 0x1048a3638, 0x1048a3658) failed, errno 2
==10401== EXEC FAILED: I can't recover from execve() failing, so I'm dying.
==10401== Add more stringent tests in PRE(sys_execve), or work out how to recover.
```


This happens only on MacOS, I tried it on Ubuntu and its working fine.
Comment 1 Rhys Kidd 2018-06-03 19:40:48 UTC
I think your code may have a subtle bug in it. To test this can you run in a Terminal window within the relevant testing folder:

// How does the program loader find the JS interpreter?
$ ./worker

I believe your main.js should be changed as follows:

> - var child = cp.fork('./worker');
> + var child = cp.fork('worker.js');
Comment 2 Rhys Kidd 2018-08-20 00:37:09 UTC
Any further feedback Nazar?
Will close this report unless able to establish this is indeed a Valgrind bug, not an application bug.