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
Fix `execa()` crashing when spawning fails with `EMFILE` or `ENFILE`Sindre Sorhusbefore adoption15c46cd
lines 1–27why, one step back1#!/usr/bin/env node2import {openSync, closeSync} from 'node:fs';3import process from 'node:process';4import {execa} from '../../index.js';56// Open files until none can be opened anymore, so that spawning fails with EMFILE7const fileDescriptors = [];8try {9 while (true) {10 fileDescriptors.push(openSync(process.execPath, 'r'));11 }12} catch {13 // No file descriptor is left14}1516let error;17try {18 await execa(process.execPath, ['--version']);19} catch (error_) {20 error = error_;21}2223for (const fileDescriptor of fileDescriptors) {24 closeSync(fileDescriptor);25}2627console.log(`${error.name} ${error.code}`);