Skip to content

Fix deleting temp file when spooling large stream to disk in StreamWrapper - #4190

Merged
sehrope merged 1 commit into
pgjdbc:masterfrom
sehrope:fix-delete-temp-file-spooling-to-disk
Jun 16, 2026
Merged

sehrope merged 1 commit into
pgjdbc:masterfrom
sehrope:fix-delete-temp-file-spooling-to-disk

Conversation

@sehrope

@sehrope sehrope commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

The cleanup block catches the rest of exception types but is noticeably missing handling for IOException. So if there's an error writing to the file, the temp file will stay on disk. Even though it's a checked exception, this wasn't noticed because the outer try-catch handling IOException.

Fix is to just add that additional exception type in the catch. It'll get rethrown immediately after attempting to remove the temp file so there's no change in error handling behavior either.

…eption

The cleanup catch in StreamWrapper(InputStream) handled
RuntimeException, Error, and PSQLException, but the most likely failure
inside that block is an IOException from copyStream or write. An
IOException bypassed the cleanup, propagated to the outer catch, and
was wrapped in a PSQLException, leaving the temp file on disk with no
cleaner registered to delete it. Every I/O failure while spooling a
large stream to disk leaked a file in the temp directory.

IOException is now included in the cleanup multi catch so the temp file
is deleted before the exception is wrapped and rethrown.
@sehrope
sehrope merged commit 02b82ad into pgjdbc:master Jun 16, 2026
16 checks passed
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