user_mda user_mda - 3 months ago 18
Java Question

Broken Pipe exception in Dropwizard application

I am getting a 'broken pipe' exception when the server is left running for a long time without any http requests. Upon some investigation I found that this exception occures because the server closes its database connection and occurs when a client requests resources when the connection is close. To fix this I added the following to the jdbc conenction url

?autoReconnect=true


I also upped the heap memory on the machine just in case. Also there are not many http clients requesting resources from this dropwizard server. Is there anything else that might be going on?

The error message for reference

You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.


I there a way to configure connection pool in dropwizard application?
Or is it a good practice to change the 'interactive-timeout' and 'wait_timeout'property of mysqld to be more than 8 hours ?

Answer

Thanks for the help , I fixed this issue by adding the following to the yaml file

  1. checkConnectionWhileIdle: true
  2. checkConnectionOnReturn: true
  3. checkConnectionOnBorrow: true

And making sure all transactions are committed, rolled back in case of exceptions and sessions are closed after use.

Comments