Skip to content

Clean up multipart tempfile on segment upload failure paths - #19455

Draft
deepthi912 wants to merge 1 commit into
apache:masterfrom
deepthi912:fix-multipart-tempfile-leak-uploadSegment
Draft

Clean up multipart tempfile on segment upload failure paths#19455
deepthi912 wants to merge 1 commit into
apache:masterfrom
deepthi912:fix-multipart-tempfile-leak-uploadSegment

Conversation

@deepthi912

@deepthi912 deepthi912 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds multiPart.cleanup() to the outer finally of uploadSegment and uploadReingestedSegment so Jersey/mimepull tempfiles (MIME*.tmp under the controller's java.io.tmpdir) don't leak when the handler exits before reaching createSegmentFileFromMultipart.

Leak paths fixed

  • uploadSegment: guard-clause throws for missing DOWNLOAD_URI (case SEGMENT and case METADATA), unexpected body in case URI, default case
  • uploadReingestedSegment: pre-try guard throws (wrong UPLOAD_TYPE / missing DOWNLOAD_URI / COPY_SEGMENT_TO_DEEP_STORE != true) — moved inside the existing try so the new finally covers them

The existing multiPart.cleanup() inside createSegmentFileFromMultipart is kept for defense in depth. MIMEPart.close() is idempotent, so double-invocation on the success path is safe.

Not covered

Leaks that no per-handler finally can catch — JVM death, IOException from mimepull during body spool, client disconnect — need a separate startup reaper for stale MIME*.tmp. Out of scope for this PR.

@codecov-commenter

codecov-commenter commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.65%. Comparing base (1ccc708) to head (42c225c).

Files with missing lines Patch % Lines
...ces/PinotSegmentUploadDownloadRestletResource.java 50.00% 2 Missing ⚠️
...er/api/resources/LLCSegmentCompletionHandlers.java 0.00% 1 Missing ⚠️
...r/api/resources/PinotIngestionRestletResource.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19455      +/-   ##
============================================
+ Coverage     67.64%   67.65%   +0.01%     
  Complexity     1430     1430              
============================================
  Files          3488     3488              
  Lines        224396   224400       +4     
  Branches      35422    35425       +3     
============================================
+ Hits         151788   151818      +30     
+ Misses        60577    60561      -16     
+ Partials      12031    12021      -10     
Flag Coverage Δ
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-25 67.65% <42.85%> (+0.01%) ⬆️
lane-a 100.00% <ø> (ø)
lane-b 0.00% <ø> (ø)
temurin 67.65% <42.85%> (+0.01%) ⬆️
unittests 67.65% <42.85%> (+0.01%) ⬆️
unittests1 57.81% <ø> (+0.01%) ⬆️
unittests2 39.34% <42.85%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@deepthi912
deepthi912 force-pushed the fix-multipart-tempfile-leak-uploadSegment branch from 87dc5d4 to 2f436c1 Compare September 4, 2026 07:12
Adds multiPart.cleanup() at the outer finally of four controller REST
endpoints that receive FormDataMultiPart so that Jersey/mimepull temp
files (MIME*.tmp on the controller's java.io.tmpdir) do not leak on
failure paths.

Endpoints fixed:
- PinotSegmentUploadDownloadRestletResource.uploadSegment (case
  SEGMENT/METADATA guard-clause throws, case URI with unexpected body,
  default case)
- PinotSegmentUploadDownloadRestletResource.uploadReingestedSegment
  (any post-try exception)
- PinotIngestionRestletResource.ingestFromFile (any exception in the
  ingestData delegation)
- LLCSegmentCompletionHandlers.extractSegmentMetadataFromForm
  (segmentCommitEndWithMetadata's only cleanup path)

Ownership centralization:
- Removed the inner multiPart.cleanup() from
  createSegmentFileFromMultipart (called by uploadSegment and
  uploadReingestedSegment) and from FileIngestionHelper.copyMultipartToLocal
  (called by ingestFromFile via ingestData). The outer REST endpoint
  now owns the multipart lifecycle. Comments added documenting this.

Not covered:
- JVM death or IOException from mimepull during body spool - no finally
  can run for those; needs a separate reaper.
- uploadSegments/uploadReingestedSegment pre-try validation throws
  (missing tableName, wrong upload type, etc.) - protocol errors from
  malformed clients; kept out of scope for this cleanup fix.
@deepthi912
deepthi912 force-pushed the fix-multipart-tempfile-leak-uploadSegment branch from 2f436c1 to 42c225c Compare September 4, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants