Skip to content

Avoid leaking temp file when disk limit is exceeded in PartGenerator - #37534

Closed
namest504 wants to merge 0 commit into
spring-projects:mainfrom
namest504:multipart-tempfile-cleanup
Closed

namest504 wants to merge 0 commit into
spring-projects:mainfrom
namest504:multipart-tempfile-cleanup

Conversation

@namest504

Copy link
Copy Markdown
Contributor

When a part exceeds maxInMemorySize, PartGenerator.InMemoryState.switchToFile() creates the temporary file and the FileState first and only then replays the buffered content into it. If that content already exceeds maxDiskUsagePerPart, FileState.onBody() throws the limit exception before the new state is installed, so the cleanup in PartGenerator.onBody() only disposes the in-memory state and the temporary file is left behind in the storage directory. This happens whenever maxDiskUsagePerPart < maxInMemorySize + bufferSize; the existing test for gh-37238 leaves such a file in java.io.tmpdir as well.

This change checks the disk usage limit before creating the file, consistent with the reactive PartGenerator (gh-37285), and releases the current buffer as required by PartListener.onBody(). The added test drives PartGenerator with a @TempDir and asserts that no file remains.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 21, 2026
@namest504
namest504 force-pushed the multipart-tempfile-cleanup branch from c31e73c to 649bf19 Compare October 22, 2026 00:03
@bclozel bclozel self-assigned this Oct 22, 2026
@bclozel
bclozel changed the base branch from main to 7.0.x October 22, 2026 08:11
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 22, 2026
@bclozel bclozel added this to the 7.0.11 milestone Oct 22, 2026
@bclozel
bclozel changed the base branch from 7.0.x to main October 22, 2026 08:13
@bclozel bclozel modified the milestones: 7.0.11, 7.1.0-RC2 Oct 22, 2026
@bclozel bclozel closed this Oct 22, 2026
@bclozel
bclozel force-pushed the multipart-tempfile-cleanup branch from 649bf19 to d86e9fc Compare October 22, 2026 08:15
@namest504
namest504 deleted the multipart-tempfile-cleanup branch October 22, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants