diff options
author | Ujjwal Sharma <usharma1998@gmail.com> | 2018-03-22 22:47:39 +0530 |
---|---|---|
committer | Trivikram <16024985+trivikr@users.noreply.github.com> | 2018-03-28 16:18:10 -0700 |
commit | ff7c2ccf230d0fd43402229da38a238ea1ee039f (patch) | |
tree | 77f6a8e5c00b0e73824f64497fd10aada0e518a4 /test/parallel/test-child-process-fork-closed-channel-segfault.js | |
parent | 7e07687230894e2c8d84e91e71251d21609e062e (diff) | |
download | android-node-v8-ff7c2ccf230d0fd43402229da38a238ea1ee039f.tar.gz android-node-v8-ff7c2ccf230d0fd43402229da38a238ea1ee039f.tar.bz2 android-node-v8-ff7c2ccf230d0fd43402229da38a238ea1ee039f.zip |
test: rename tests with descriptive filenames
Refs: https://github.com/nodejs/node/issues/19105
Refs: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#test-structure
PR-URL: https://github.com/nodejs/node/pull/19608
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/parallel/test-child-process-fork-closed-channel-segfault.js')
-rw-r--r-- | test/parallel/test-child-process-fork-closed-channel-segfault.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-fork-closed-channel-segfault.js b/test/parallel/test-child-process-fork-closed-channel-segfault.js new file mode 100644 index 0000000000..87b599c7bb --- /dev/null +++ b/test/parallel/test-child-process-fork-closed-channel-segfault.js @@ -0,0 +1,75 @@ +'use strict'; +const common = require('../common'); + +// Before https://github.com/nodejs/node/pull/2847 a child process trying +// (asynchronously) to use the closed channel to it's creator caused a segfault. + +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); + +if (!cluster.isMaster) { + // Exit on first received handle to leave the queue non-empty in master + process.on('message', function() { + process.exit(1); + }); + return; +} + +const server = net + .createServer(function(s) { + if (common.isWindows) { + s.on('error', function(err) { + // Prevent possible ECONNRESET errors from popping up + if (err.code !== 'ECONNRESET') throw err; + }); + } + setTimeout(function() { + s.destroy(); + }, 100); + }) + .listen(0, function() { + const worker = cluster.fork(); + + function send(callback) { + const s = net.connect(server.address().port, function() { + worker.send({}, s, callback); + }); + + // https://github.com/nodejs/node/issues/3635#issuecomment-157714683 + // ECONNREFUSED or ECONNRESET errors can happen if this connection is + // still establishing while the server has already closed. + // EMFILE can happen if the worker __and__ the server had already closed. + s.on('error', function(err) { + if ( + err.code !== 'ECONNRESET' && + err.code !== 'ECONNREFUSED' && + err.code !== 'EMFILE' + ) { + throw err; + } + }); + } + + worker.process.once( + 'close', + common.mustCall(function() { + // Otherwise the crash on `channel.fd` access may happen + assert.strictEqual(worker.process.channel, null); + server.close(); + }) + ); + + worker.on('online', function() { + send(function(err) { + assert.ifError(err); + send(function(err) { + // Ignore errors when sending the second handle because the worker + // may already have exited. + if (err && err.message !== 'Channel closed') { + throw err; + } + }); + }); + }); + }); |