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

Fix flaky test-child-process-emfile #3430

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions test/sequential/test-child-process-emfile.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var fs = require('fs');
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');
const fs = require('fs');

if (common.isWindows) {
console.log('1..0 # Skipped: no RLIMIT_NOFILE on Windows');
return;
}

var openFds = [];
const ulimit = Number(child_process.execSync('ulimit -Hn'));
if (ulimit > 64 || Number.isNaN(ulimit)) {
// Sorry about this nonsense. It can be replaced if
// https://github.com/nodejs/node-v0.x-archive/pull/2143#issuecomment-2847886
// ever happens.
const result = child_process.spawnSync(
'/bin/sh',
['-c', `ulimit -n 64 && '${process.execPath}' '${__filename}'`]
);
assert.strictEqual(result.stdout.toString(), '');
assert.strictEqual(result.stderr.toString(), '');
assert.strictEqual(result.status, 0);
assert.strictEqual(result.error, undefined);
return;
}

const openFds = [];

for (;;) {
try {
openFds.push(fs.openSync(__filename, 'r'));
} catch (err) {
assert(err.code === 'EMFILE' || err.code === 'ENFILE');
assert(err.code === 'EMFILE');
break;
}
}

// Should emit an error, not throw.
var proc = spawn(process.execPath, ['-e', '0']);
const proc = child_process.spawn(process.execPath, ['-e', '0']);

proc.on('error', common.mustCall(function(err) {
assert(err.code === 'EMFILE' || err.code === 'ENFILE');
assert.strictEqual(err.code, 'EMFILE');
}));

proc.on('exit', function() {
Expand Down