-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle ParameterStatus messages in QueryExecutorImpl.receiveFast…
…pathResult (#2247) QueryExecutorImpl.receiveFastpathResult did not properly handle ParameterStatus messages. This in turn caused failures for some LargeObjectManager operations. Fixed by adding the missing code path, based on the existing handling in processResults. Closes #2237
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
pgjdbc/src/test/java/org/postgresql/jdbc/LargeObjectManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2021, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.jdbc; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.postgresql.largeobject.LargeObjectManager; | ||
import org.postgresql.test.TestUtil; | ||
import org.postgresql.util.PSQLException; | ||
import org.postgresql.util.PSQLState; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Statement; | ||
|
||
class LargeObjectManagerTest { | ||
private PgConnection con; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
con = (PgConnection) TestUtil.openDB(); | ||
con.setAutoCommit(false); | ||
} | ||
|
||
/* | ||
* It is possible for PostgreSQL to send a ParameterStatus message after an ErrorResponse | ||
* Receiving such a message should not lead to an invalid connection state | ||
* See https://github.com/pgjdbc/pgjdbc/issues/2237 | ||
*/ | ||
@Test | ||
public void testOpenWithErrorAndSubsequentParameterStatusMessageShouldLeaveConnectionInUsableStateAndUpdateParameterStatus() throws Exception { | ||
String originalApplicationName = con.getParameterStatus("application_name"); | ||
try (Statement statement = con.createStatement()) { | ||
statement.execute("begin;"); | ||
// Set transaction application_name to trigger ParameterStatus message after error | ||
// https://www.postgresql.org/docs/14/protocol-flow.html#PROTOCOL-ASYNC | ||
String updatedApplicationName = "LargeObjectManagerTest-application-name"; | ||
statement.execute("set application_name to '" + updatedApplicationName + "'"); | ||
|
||
LargeObjectManager loManager = con.getLargeObjectAPI(); | ||
try { | ||
loManager.open(0, false); | ||
fail("Succeeded in opening a non-existent large object"); | ||
} catch (PSQLException e) { | ||
assertEquals(PSQLState.UNDEFINED_OBJECT.getState(), e.getSQLState()); | ||
} | ||
|
||
// Should be reset to original application name | ||
assertEquals(originalApplicationName, con.getParameterStatus("application_name")); | ||
} | ||
} | ||
} |