diff --git a/src/Formidable.js b/src/Formidable.js index 733ff673..192e8125 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -412,6 +412,12 @@ class IncomingForm extends EventEmitter { }); this.emit("fileBegin", part.name, file); + // Check for error after fileBegin (e.g., maxFiles exceeded) to avoid leaking file handles + if (this.error) { + this._flushing -= 1; + return; + } + file.open(); this.openedFiles.push(file);