pgjdbc: Fallback for gssEncMode connection mode is not working as expected
Describe the issue We use Azure Managed PostgreSQL. While connecting to the DB using the latest driver (and default connection string) we receive failure (stacktrace in logs).
It seems the connection is closed prematurely without the ability to use different connection (encryption) type.
Providing “gssEncMode=disable” fixe the problem, but I would expect such breaking change in patch release.
Driver Version? Anything above 42.2.14. Reproduced on 42.2.15 and 42.2.16
Java Version? Java 11 OpenJDK (coming from following Docker Image: hmctspublic.azurecr.io/imported/distroless/java:11)
OS Version? Distroless docker image (minimalistic debian, glibc based image). Shouldn’t matter as it seems to be generic problem (failed on my local MacOS 10.15.4
PostgreSQL Version? PostgreSQL managed version 10. (not sure what’s the exact version number, I don’t think it’s specified).
To Reproduce Steps to reproduce the behaviour:
- In Azure Provision Managed PostgreSQL.
- Try connecting to it using the provided code:
String url = "jdbc:postgresql://xxx5432/xxx?loggerLevel=TRACE&loggerFile=pgjdbc-trace.log";
Properties props = new Properties();
props.setProperty("user", "user");
props.setProperty("password", "pw");
try ( Connection conn = DriverManager.getConnection(url, props) ){
Expected behaviour I am connected to the DB without any problems.
Exception is thrown as specified in the logs. Logs From driver test:
Aug 25, 2020 4:02:56 PM org.postgresql.Driver connect
FINE: Connecting with URL: jdbc:postgresql://xxx:5432/xxx?loggerLevel=TRACE&loggerFile=pgjdbc-trace.log
Aug 25, 2020 4:02:56 PM org.postgresql.jdbc.PgConnection <init>
FINE: PostgreSQL JDBC Driver 42.2.16
Aug 25, 2020 4:02:56 PM org.postgresql.jdbc.PgConnection setDefaultFetchSize
FINE: setDefaultFetchSize = 0
Aug 25, 2020 4:02:56 PM org.postgresql.jdbc.PgConnection setPrepareThreshold
FINE: setPrepareThreshold = 5
Aug 25, 2020 4:02:56 PM org.postgresql.core.v3.ConnectionFactoryImpl openConnectionImpl
FINE: Trying to establish a protocol version 3 connection to xxx:5432
Aug 25, 2020 4:02:56 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Aug 25, 2020 4:02:56 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Aug 25, 2020 4:02:56 PM org.postgresql.core.Encoding <init>
FINEST: Creating new Encoding UTF-8 with fastASCIINumbers true
Aug 25, 2020 4:02:56 PM org.postgresql.core.v3.ConnectionFactoryImpl tryConnect
FINE: Receive Buffer Size is 131,376
Aug 25, 2020 4:02:56 PM org.postgresql.core.v3.ConnectionFactoryImpl tryConnect
FINE: Send Buffer Size is 131,376
Aug 25, 2020 4:02:56 PM org.postgresql.core.v3.ConnectionFactoryImpl enableGSSEncrypted
FINEST: FE=> GSSENCRequest
Aug 25, 2020 4:02:56 PM org.postgresql.Driver connect
FINE: Connection error:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
at org.postgresql.Driver.makeConnection(Driver.java:465)
at org.postgresql.Driver.connect(Driver.java:264)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
at mycode.main(MyCode:34)
Caused by: java.io.EOFException
at org.postgresql.core.PGStream.receiveChar(PGStream.java:443)
at org.postgresql.core.v3.ConnectionFactoryImpl.enableGSSEncrypted(ConnectionFactoryImpl.java:436)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:144)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
... 7 more
Thanks appreciate any input!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 31 (16 by maintainers)
Links to this issue
- Beschränkungen – Azure Database for PostgreSQL – Einzelserver | Microsoft Learn
- Are you running into Postgres connection issues on Azure? - Microsoft Community Hub
- Limits - Azure Database for PostgreSQL - Single Server | Microsoft Learn
- Ограничения в Базе данных Azure для PostgreSQL (отдельный сервер) | Microsoft Learn
- Limites - Servidor Único do Banco de Dados do Azure para PostgreSQL | Microsoft Learn
- Limites - Azure Database pour PostgreSQL - Serveur unique | Microsoft Learn
- Limity — Azure Database for PostgreSQL — pojedynczy serwer | Microsoft Learn
- 限制 - Azure Database for PostgreSQL(单一服务器) | Microsoft Learn
- Límites en Azure Database for PostgreSQL: servidor único | Microsoft Learn
- 制限 - Azure Database for PostgreSQL - Single Server | Microsoft Learn
- Limity – Azure Database for PostgreSQL – Jednoúčelový server | Microsoft Learn
- حدود - قاعدة بيانات Azure لـ PostgreSQL - خادم فردي | Microsoft Learn
Commits related to this issue
- fix: set default GSSEncMode to allow instead of prefer as it requires configuration on the server side to work it's probably not a sane default for connections see #1909 and #1868 — committed to nstapelbroek/pgjdbc by nstapelbroek 4 years ago
- Replace PostgreSQL JDBC version with 42.2.19 42.2.15 - 42.2.17 have an issue with older PosgreSQL versions. See: - https://github.com/pgjdbc/pgjdbc/issues/1868 - https://github.com/SonarSource/sonar... — committed to porscheinformatik/docker-sonarqube by derkoe 3 years ago
- DBZ-4060 Update `pgjdbc` to 42.2.22 to fix connection issues This is to solve connection issues on Google Cloud SQL and Azure relating to this issue: https://github.com/pgjdbc/pgjdbc/issues/1868 — committed to judahrand/debezium by judahrand 3 years ago
- DBZ-4060 Update `pgjdbc` to 42.2.22 to fix connection issues This is to solve connection issues on Google Cloud SQL and Azure relating to this issue: https://github.com/pgjdbc/pgjdbc/issues/1868 — committed to debezium/debezium by judahrand 3 years ago
- DBZ-4060 Update `pgjdbc` to 42.2.22 to fix connection issues This is to solve connection issues on Google Cloud SQL and Azure relating to this issue: https://github.com/pgjdbc/pgjdbc/issues/1868 — committed to roldanbob/debezium by judahrand 3 years ago
fixed with pr #1883
@dentonmwood What is going on is this. GssEncryption will send a new startup sequence to ask the server if it wants GSS encryption. Some cloud providers just closed the connection if they received this as they didn’t implement the protocol correctly. So when you set gssEncMode to disable it just does not attempt that startup sequence. There should be no ill effects if you set it to disable. Cheers,
I think it might be related to PGPool, this is what I found on PGPool’s site
So my guess is that since 42.2.x where the default was set to “allow” (or “prefer”?) PGPool can’t deal with it anymore. A workaround for us is to temporarily add
gssEncMode=disableto our JDBC URLs.Awesome, thanks for the quick turnaround