Skip to content

fix(handler): remove multipart temp files when the request fails to parse - #314

Merged
rustatian merged 1 commit into
masterfrom
fix/multipart-tempfile-cleanup
Nov 24, 2026
Merged

rustatian merged 1 commit into
masterfrom
fix/multipart-tempfile-cleanup

Conversation

@rustatian

Copy link
Copy Markdown
Member

Reason for This PR

A multipart request with file parts can fail to build the upload tree, for example with two file fields a and a[b]. Then the temp files of the parsed form stay on disk. The HTTP/1.1 and HTTP/2 servers remove them after the handler returns, but the HTTP/3 and FastCGI servers do not.

Description of Changes

  • Request.Close removes the parsed multipart form on every error path, also when the upload tree was not built.
  • A new handler test sends a request with conflicting file fields and checks that no temp file stays on disk.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

…arse

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added bug Something isn't working go Pull requests that update Go code labels Nov 24, 2026
Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:15
@rustatian rustatian self-assigned this Nov 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.43%. Comparing base (6205c95) to head (a4bd7bf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #314      +/-   ##
==========================================
+ Coverage   90.28%   90.43%   +0.14%     
==========================================
  Files          29       29              
  Lines        1348     1348              
==========================================
+ Hits         1217     1219       +2     
+ Misses        131      129       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rustatian
rustatian merged commit aff007f into master Nov 24, 2026
8 checks passed
@rustatian
rustatian deleted the fix/multipart-tempfile-cleanup branch November 24, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants