Skip to content

Demo project for a Google Cloud SQL JDBC driver hang

Notifications You must be signed in to change notification settings

luryus/cloud-sql-jdbc-hang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloud SQL JDBC Driver Hang Repro

This repo contains a simple sample project that demos a hang in the Cloud SQL JDBC Postgres driver. The hang happens on Windows, when Windows either sleeps or hibernates.

The issue seems to be a bug in the driver: internal timers for refreshing certificates do not trigger on time when Windows has been asleep. This causes the driver to try to create a connection with an outdated certificate, which obviously fails.

There seems to be no way to work around the issue except restarting the process.

Running

Requirements

Java 17, Gradle. Cloud SDK installed and application-default login done, authenticated as an user with permissions to connect to a Cloud SQL postgres instance. Username and password available to that database.

Running

  1. Open a command prompt (cmd) in Windows.
  2. cd to the project directory.
  3. Set the database user password in the DB_PASSWORD environment variable
    SET "DB_PASSWORD=<password>"
  4. Build a jdbc connection string for the target Cloud SQL instance. E.g. jdbc:postgresql:///databasename?cloudSqlInstance=gcp-project:europe-west3:sql-instance-1&user=username
  5. Run the program, giving the connection string from the previous step as a CLI argument
    gradlew app:run --args "jdbc:postgresql:///databasename?cloudSqlInstance=gcp-project:europe-west3:sql-instance-1&user=username"
  6. The program will connect and start periodically checking the connection status. If the connection fails, a reconnection is attempted.
  7. Put the Windows PC to sleep and let it be for at least an hour.
  8. Wake the computer after the ephemeral certs have expired (1 hour). The logs will show that the connection has failed during sleep (of course), but the reconnection also fails.
  9. If the program is left alone for about an hour (depending on how quickly the PC was put to sleep after the program started), the connections should eventually recover as the JDBC library finally refreshes the certs.

About

Demo project for a Google Cloud SQL JDBC driver hang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages