-
-
Notifications
You must be signed in to change notification settings - Fork 689
fix: prevent file handle leak when maxFiles is exceeded #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
Comment on lines
+415
to
+419
|
||
|
|
||
| file.open(); | ||
| this.openedFiles.push(file); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the multipart path, but the same maxFiles/fileBegin sequencing exists in the octet-stream plugin (src/plugins/octetstream.js): it emits
fileBeginbeforefile.open()andopenedFiles.push(file). IfmaxFilesis exceeded there,_error()will run before the file is tracked and the handle can still leak. Consider applying the samethis.errorshort-circuit (and matching_flushinghandling) in the octet-stream code path as well to make the fix comprehensive.