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:

  1. In Azure Provision Managed PostgreSQL.
  2. 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)

Commits related to this issue

Most upvoted comments

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

Support GSSAPI

Pgpool-II does not support it yet. Moreover if client sends request with "gssencmode=prefer" Pgpool-II fails.

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=disable to our JDBC URLs.

Awesome, thanks for the quick turnaround