fs: improve fs.watch ENOSPC error message
Providing `No space left on device` is misleading in this case. Replace it with something that describes it more accurately. Refs: https://stackoverflow.com/questions/22475849/node-js-error-enospc/32600959 PR-URL: https://github.com/nodejs/node/pull/21846 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
ee31c28298
commit
13245dc50d
@ -249,7 +249,7 @@ function getMessage(key, args) {
|
|||||||
*/
|
*/
|
||||||
function uvException(ctx) {
|
function uvException(ctx) {
|
||||||
const [ code, uvmsg ] = errmap.get(ctx.errno);
|
const [ code, uvmsg ] = errmap.get(ctx.errno);
|
||||||
let message = `${code}: ${uvmsg}, ${ctx.syscall}`;
|
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
|
||||||
|
|
||||||
let path;
|
let path;
|
||||||
let dest;
|
let dest;
|
||||||
|
@ -7,6 +7,7 @@ const {
|
|||||||
StatWatcher: _StatWatcher
|
StatWatcher: _StatWatcher
|
||||||
} = process.binding('fs');
|
} = process.binding('fs');
|
||||||
const { FSEvent } = internalBinding('fs_event_wrap');
|
const { FSEvent } = internalBinding('fs_event_wrap');
|
||||||
|
const { UV_ENOSPC } = internalBinding('uv');
|
||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
const {
|
const {
|
||||||
getStatsFromBinding,
|
getStatsFromBinding,
|
||||||
@ -165,7 +166,9 @@ FSWatcher.prototype.start = function(filename,
|
|||||||
const error = errors.uvException({
|
const error = errors.uvException({
|
||||||
errno: err,
|
errno: err,
|
||||||
syscall: 'watch',
|
syscall: 'watch',
|
||||||
path: filename
|
path: filename,
|
||||||
|
message: err === UV_ENOSPC ?
|
||||||
|
'System limit for number of file watchers reached' : ''
|
||||||
});
|
});
|
||||||
error.filename = filename;
|
error.filename = filename;
|
||||||
throw error;
|
throw error;
|
||||||
|
51
test/sequential/test-fs-watch-system-limit.js
Normal file
51
test/sequential/test-fs-watch-system-limit.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const child_process = require('child_process');
|
||||||
|
const stream = require('stream');
|
||||||
|
|
||||||
|
if (!common.isLinux)
|
||||||
|
common.skip('The fs watch limit is OS-dependent');
|
||||||
|
if (!common.enoughTestCpu)
|
||||||
|
common.skip('This test is resource-intensive');
|
||||||
|
|
||||||
|
const processes = [];
|
||||||
|
const gatherStderr = new stream.PassThrough();
|
||||||
|
gatherStderr.setEncoding('utf8');
|
||||||
|
gatherStderr.setMaxListeners(Infinity);
|
||||||
|
|
||||||
|
let finished = false;
|
||||||
|
function spawnProcesses() {
|
||||||
|
for (let i = 0; i < 10; ++i) {
|
||||||
|
const proc = child_process.spawn(
|
||||||
|
process.execPath,
|
||||||
|
[ '-e',
|
||||||
|
`process.chdir(${JSON.stringify(__dirname)});
|
||||||
|
for (const file of fs.readdirSync('.'))
|
||||||
|
fs.watch(file, () => {});`
|
||||||
|
], { stdio: ['inherit', 'inherit', 'pipe'] });
|
||||||
|
proc.stderr.pipe(gatherStderr);
|
||||||
|
processes.push(proc);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!finished && processes.length < 200)
|
||||||
|
spawnProcesses();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
spawnProcesses();
|
||||||
|
|
||||||
|
let accumulated = '';
|
||||||
|
gatherStderr.on('data', common.mustCallAtLeast((chunk) => {
|
||||||
|
accumulated += chunk;
|
||||||
|
if (accumulated.includes('Error:') && !finished) {
|
||||||
|
assert(
|
||||||
|
accumulated.includes('ENOSPC: System limit for number ' +
|
||||||
|
'of file watchers reached'),
|
||||||
|
accumulated);
|
||||||
|
console.log(`done after ${processes.length} processes, cleaning up`);
|
||||||
|
finished = true;
|
||||||
|
processes.forEach((proc) => proc.kill());
|
||||||
|
}
|
||||||
|
}, 1));
|
Loading…
x
Reference in New Issue
Block a user