Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting JDBC to retry upon startup #1218

Closed
aclowkey opened this issue Jul 17, 2018 · 2 comments
Closed

Getting JDBC to retry upon startup #1218

aclowkey opened this issue Jul 17, 2018 · 2 comments
Labels
Milestone

Comments

@aclowkey
Copy link
Contributor

If the JDBC connection won't work on startup, Jooby will hang forever.

I've encountered the issue when deploying a Kubernetes cluster, my Jooby instance starts faster than MySQL and gets communication link failure and just hangs. As soon as MySQL start it keeps running, while Jooby is hanging 😴

Is there a way to configure either Jooby or HikariCP to try to reconnect periodically?

@jknack
Copy link
Member

jknack commented Jul 17, 2018

This is HikariCP question, but what is the exception?

Seems HikariCP handles connection retries brettwooldridge/HikariCP#907

Also, have a look at https://github.com/brettwooldridge/HikariCP/wiki/Bad-Behavior:-Handling-Database-Down

@aclowkey
Copy link
Contributor Author

I found the reason, initializationFailTimeout is by default set to 1, so if a connection cannot be made the pool will fail fast. Setting it to -1 will bypass that, and will try to get connection in background.

I've tried it as follows

  1. Shutdown MySQL
  2. Start jooby (Start successfully
  3. Query my database dependent endpoint - fails on connection refused
  4. Start MySQL
  5. Query the endpoint again. Now it works!

Quote from HikariCP documentation:

A value less than zero will bypass any initial connection attempt, and the pool will start immediately while trying to obtain connections in the background. Consequently, later efforts to obtain a connection may fail. Default: 1

@jknack jknack added this to the 1.5.1 milestone Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants