Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backpatch [PR #2143](https://github.com/pgjdbc/pgjdbc/pull/2143) read notifies or errors that come in asynchronously after the ready for query #2168

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,19 @@ public synchronized void execute(Query query, @Nullable ParameterList parameters
LOGGER.log(Level.FINEST, " simple execute, handler={0}, maxRows={1}, fetchSize={2}, flags={3}",
new Object[]{handler, maxRows, fetchSize, flags});
}

try {
if (pgStream.hasMessagePending()) {
if (pgStream.peekChar() == 'N') {
pgStream.receiveChar();
handler.handleWarning(receiveNoticeResponse());
} else if (pgStream.peekChar() == 'E') {
pgStream.receiveChar();
throw receiveErrorResponse();
}
}
} catch ( IOException ex ) {
throw new SQLException(ex);
}
if (parameters == null) {
parameters = SimpleQuery.NO_PARAMETERS;
}
Expand Down Expand Up @@ -2312,6 +2324,7 @@ protected void processResults(ResultHandler handler, int flags) throws IOExcepti
}

case 'N': // Notice Response
LOGGER.log(Level.FINEST, " <=BE Notice");
SQLWarning warning = receiveNoticeResponse();
handler.handleWarning(warning);
break;
Expand Down Expand Up @@ -2369,7 +2382,16 @@ && castNonNull(pendingExecuteQueue.peekFirst()).asSimple) {
}
}
endQuery = true;

if (pgStream.hasMessagePending()) {
if (pgStream.peekChar() == 'N') {
pgStream.receiveChar();
handler.handleWarning(receiveNoticeResponse());
}
if (pgStream.peekChar() == 'E') {
pgStream.receiveChar();
handler.handleError(receiveErrorResponse());
}
}
// Reset the statement name of Parses that failed.
while (!pendingParseQueue.isEmpty()) {
SimpleQuery failedQuery = pendingParseQueue.removeFirst();
Expand Down
2 changes: 2 additions & 0 deletions pgjdbc/src/main/java/org/postgresql/util/PSQLState.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public enum PSQLState {
SYSTEM_ERROR("60000"),
IO_ERROR("58030"),

ERROR_CODE_CRASH_SHUTDOWN("57P02"),

UNEXPECTED_ERROR("99999");

private final String state;
Expand Down
3 changes: 2 additions & 1 deletion pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ public void testLockReleaseOnCancelFailure() throws SQLException, InterruptedExc
if (rollbackException == null) {
fail("rollback should have thrown an exception");
}
acceptIOCause(rollbackException);

assertTrue( rollbackException instanceof SQLException);
}

private static class Rollback extends Thread {
Expand Down