Message-ID: From: "sehrope (@sehrope)" To: "pgjdbc/pgjdbc" Date: Mon, 15 Jun 2026 20:33:11 +0000 Subject: [pgjdbc/pgjdbc] PR #4190: Fix deleting temp file when spooling large stream to disk in StreamWrapper List-Id: X-GitHub-Additions: 1 X-GitHub-Author-Id: 1690926 X-GitHub-Author-Login: sehrope X-GitHub-Base: master X-GitHub-Changed-Files: 1 X-GitHub-Commits: 1 X-GitHub-Deletions: 1 X-GitHub-Head-Branch: fix-delete-temp-file-spooling-to-disk X-GitHub-Head-SHA: 1ab8a4d634b9a167734baacd447fba06f23b11e2 X-GitHub-Issue: 4190 X-GitHub-Merge-SHA: 02b82aded078f2dfacb9db7579ad9ed7b0d3db67 X-GitHub-Merged-By: sehrope X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: merged X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/pull/4190 Content-Type: text/plain; charset=utf-8 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. diff --git a/pgjdbc/src/main/java/org/postgresql/util/StreamWrapper.java b/pgjdbc/src/main/java/org/postgresql/util/StreamWrapper.java index 8c1190d192..c10f9efd83 100644 --- a/pgjdbc/src/main/java/org/postgresql/util/StreamWrapper.java +++ b/pgjdbc/src/main/java/org/postgresql/util/StreamWrapper.java @@ -60,7 +60,7 @@ public StreamWrapper(InputStream stream) throws PSQLException { throw new PSQLException(GT.tr("Object is too large to send over the protocol."), PSQLState.NUMERIC_CONSTANT_OUT_OF_RANGE); } - } catch (RuntimeException | Error | PSQLException e) { + } catch (RuntimeException | Error | PSQLException | IOException e) { try { tempFile.toFile().delete(); } catch (Throwable ignore) {