Skip to content

Commit 178784c

Browse files
committed
fix: prevent file handle leak when maxFiles is exceeded
Fixes #987 When maxFiles limit is reached, the fileBegin event handler calls _error(), but _handlePart continues and opens a write stream for the new file. These file handles are never closed. Fix: check this.error after emitting fileBegin and before file.open(). If an error occurred (e.g., maxFiles exceeded), decrement _flushing and return early to prevent the file stream from being opened.
1 parent 44768be commit 178784c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/Formidable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ class IncomingForm extends EventEmitter {
403403
});
404404
this.emit('fileBegin', part.name, file);
405405

406+
// Check for error after fileBegin (e.g., maxFiles exceeded) to avoid leaking file handles
407+
if (this.error) {
408+
this._flushing -= 1;
409+
return;
410+
}
411+
406412
file.open();
407413
this.openedFiles.push(file);
408414

0 commit comments

Comments
 (0)