emfile.js
This file
Path
test/fixtures/emfile.js
27 lines · 603 bytes · JavaScript
Last changed by
Fix `execa()` crashing when spawning fails with `EMFILE` or `ENFILE`Sindre Sorhusbefore adoption15c46cd
History of this fileTake it
12345678910111213141516171819202122232425262728#!/usr/bin/env nodeimport {openSync, closeSync} from 'node:fs';import process from 'node:process';import {execa} from '../../index.js';
// Open files until none can be opened anymore, so that spawning fails with EMFILEconst fileDescriptors = [];try { while (true) { fileDescriptors.push(openSync(process.execPath, 'r')); }} catch { // No file descriptor is left}
let error;try { await execa(process.execPath, ['--version']);} catch (error_) { error = error_;}
for (const fileDescriptor of fileDescriptors) { closeSync(fileDescriptor);}
console.log(`${error.name} ${error.code}`);