Skip to content

Commit

Permalink
fix: backpatch2142 read notifies or errors that come in asynchronousl…
Browse files Browse the repository at this point in the history
…y after the ready for query (#2168)
  • Loading branch information
davecramer committed May 31, 2021
1 parent 1747652 commit 4fa2d5b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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') {

This comment has been minimized.

Copy link
@robsonpeixoto

robsonpeixoto Jun 19, 2021

Sorry the noob question, but why here is using a else if and on line 2390 is only using only a if?

This comment has been minimized.

Copy link
@davecramer

davecramer Jun 20, 2021

Author Member

Excellent question. No real reason. Compiler probably optimizes it out. Either way I am going to have to revert it as it causes a regression. There's no easy way to fix this

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

0 comments on commit 4fa2d5b

Please sign in to comment.