Hikaricp: Illegal argument for PostgreSQL JDBC setNetworkTimeout

Created on 4 Feb 2018  路  7Comments  路  Source: brettwooldridge/HikariCP

Environment

HikariCP version: 2.7.6
JDK version     : 1.8.0_111
Database        : PostgreSQL
Driver version  : 42.2.1
G Cloud SQL Socket Factory version: 1.0.5

I'm using HickariCP with Google App Engine Standard and Google Cloud SQL Socket Factory to deploy an Java 8 API and facing a PSQLException that is thrown most of the times I upload the app to GAE.

Some important points:

  • The updates with support for the socket factory are just a few days old and PGSQL is beta on GAE AFAIK, so I'm not 100% sure if the problem is with HikariCP or the driver or the socket factory;
  • When connecting to database as a external application (without Google Cloud Socket Factory), everything works just fine (except the fact I need to allow any IP address to connect to my DB instance - each new instance seems to have a different IP, so I need to white list all);
  • The PSQLException if refer is thrown at this line and indicates that an negative value was passed as argument to the PgConnection.setNetworkTimeout;
  • If I set the connection timeout on code or Properties, the error occurs the same way.
  • After several tries I'm able to make it work, just by re-submitting the code again and again.
  • I've tried warming up the instance, deleting and recreating services, updating existing versions and creating new ones.

Here is the log:

javax.servlet.ServletContext log: RestletServlet: [Restlet] Attaching application: br.com.appkizumba.api.WebApiApplication@4dd025df to URI: /v1
org.restlet.Application start: Starting br.com.appkizumba.api.WebApiApplication application (Application.java:589)
INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
com.google.cloud.sql.postgres.SocketFactory createSocket: Connecting to Cloud SQL instance [...]. (SocketFactory.java:55)
com.google.cloud.sql.postgres.SocketFactory createSocket: GAE Unix Sockets (SocketFactory.java:63)
[Request11B37C49] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: Network timeout must be a value greater than or equal to 0.
    at org.postgresql.jdbc.PgConnection.setNetworkTimeout(PgConnection.java:1540)
    at com.zaxxer.hikari.pool.PoolBase.setNetworkTimeout(PoolBase.java:551)
    at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:438)
question

All 7 comments

@MathiasBerwig To me this looks like an issue with GAE, but possibly a driver issue. The exception above indicates that the driver returned a negative number as the current network timeout setting. When HikariCP tries to restore the default, after changing it temporarily, the driver complains.

The question is why did the driver return a negative number as the current timeout? The default should be 0 (zero), which indicates infinite timeout...

EDIT: It should be noted that this issue is not seen with the regular driver, which makes me suspect the GAE SocketFactory. I would report the issue to Google. The network timeout returned from Connection.getNetworkTimeout() should be zero (0) by default.

@MathiasBerwig +1
I'm experiencing the same issue right now, more or less same versions. Could you, just for the reference share your findings and if/how you resolved this issue? Thank you.

@maricn I did not find a reasonably secure way to fix this issue. Due to the startup-like nature of my project, I had enabled external connections and am using the regular driver and socket factory to connect to Cloud SQL by IP.

Please note that each new GAE instance will have a new and probably unknown IP address, so you'd need to whitelist any address (0.0.0.0/0). This is a huge security flaw (bots are trying to guess the password all day).

@MathiasBerwig @maricn I can investigate a "fix" (workaround) to ignore the network timeout if the get call returns a negative number. However, my strong preference would be that either or both of you two open an issue/incident report with GAE. Even if they don't support network timeout (which they should), if they just return a zero (0) value then all will be right in the world.

EDIT: If the GAE issue has a linkable URL, please post it here for future readers.

@MathiasBerwig
Thank you for your prompt response. I understand, we're in the similar position, also considering switching to GAE flex, since whitelisting everything is a no-go here.

Just for the reference, using some [or none] connection pool (eg. org.postgresql.ds.PGSimpleDataSource) circumvents the issue.

@brettwooldridge
I'm right on your side. I've created an issue with GAE

@maricn Thanks. I "starred" that issue. @MathiasBerwig I encourage you to do so as well.

I'm no longer using HikariCP as my project is no more active. Since nobody else seems to be facing this problem, I'm closing the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baumeister picture baumeister  路  3Comments

timmychiu picture timmychiu  路  5Comments

scrumvisualize picture scrumvisualize  路  5Comments

frymaster picture frymaster  路  4Comments

TuomasKiviaho picture TuomasKiviaho  路  5Comments