Message-ID: From: "jamesagnew (@jamesagnew)" To: "pgjdbc/pgjdbc" Date: Wed, 19 Feb 2025 20:02:09 +0000 Subject: [pgjdbc/pgjdbc] issue #3530: JDBC Shared Timer set to cancelled List-Id: X-GitHub-Assignees: davecramer X-GitHub-Author-Id: 3465117 X-GitHub-Author-Login: jamesagnew X-GitHub-Issue: 3530 X-GitHub-Labels: bug X-GitHub-Milestone: 42.8.0 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: closed X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3530 Content-Type: text/plain; charset=utf-8 **Describe the issue** I have a Java-based server using Postgresql as a persistence layer that occasionally gets into a state where it is completely unable to perform any new JDBC calls, requiring a JVM restart to bring it back. Once the driver is in this state, any attempt to execute any SQL statement is aborted immediately with the message: java.lang.IllegalStateException: Timer already cancelled I have observed that this always starts when the server experiences an OutOfMemoryException while processing a resultset. Obviously that shouldn't happen and that's a separate issue, but I don't think an OOM should result in the driver becoming unusable either. Shortly after an OOM, I typically see an exception with the following stack trace in my logs (presumably the JVM is unstable at this point while the GC tries to recover): ``` Caused by: org.postgresql.util.PSQLException: SSL error: Broken pipe at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:53) at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:638) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:201) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:268) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54) at org.postgresql.jdbc.PgConnection.(PgConnection.java:273) at org.postgresql.Driver.makeConnection(Driver.java:446) at org.postgresql.Driver.connect(Driver.java:298) at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:52) at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:414) ``` The exception above appears once, and then from that moment onward, all JDBC calls fail with the following stack trace: ``` Caused by: java.lang.IllegalStateException: Timer already cancelled. at java.base/java.util.Timer.sched(Timer.java:409) at java.base/java.util.Timer.schedule(Timer.java:205) at org.postgresql.jdbc.PgConnection.addTimerTask(PgConnection.java:1351) at org.postgresql.jdbc.PgStatement.startTimer(PgStatement.java:995) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:516) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:434) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:137) at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement. java:123) at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement. java:123) ``` **Driver Version?** This is occurring on 42.7.4 but this behaviour has been observed on a number of older versions as well over the last 6 months. **Java Version?** openjdk version "17.0.7" 2023-04-18 LTS OpenJDK Runtime Environment Corretto-17.0.7.7.1 (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.7.7.1 (build 17.0.7+7-LTS, mixed mode, sharing) **OS Version?** Ubuntu 24.04.2 LTS **PostgreSQL Version?** PostgreSQL 16.6 (Ubuntu 16.6-0ubuntu0.24.04.1) on x86_64-pc-linux-gnu