Dropwizard shutdown hook before http server shutdown

530 views
Skip to first unread message

n4l

unread,
Mar 26, 2019, 4:01:20 PM3/26/19
to dropwizard-user

Hi,


I have a situation with a Dropwizard service running on multiple servers in an active-active fashion behind a load balancer. The load balancer is verifying that each service instance is running by calling the "/ping" endpoint. If a response hasn't been received in 20 seconds, that service instance is considered dead and will not get any more requests until ping returns 200 again. In order to do seamless deployment, I want to have a shutdown hook such that the ping endpoint returns !200 for 20 seconds before shutting down the http server. During those 20 seconds, I want the service to function normally except for the ping response.

 

I have looked at using managed objects and using the "stop()" method, but it seems like the http server has already shutdown by then (as suggested by https://groups.google.com/forum/#!topic/dropwizard-user/UP1krCq--cA).


I have also looked at using a task like what is suggested in https://stackoverflow.com/questions/31288721/dropwizard-shutdown-hook/31296783#31296783 but I'm not a situation where I can make a http request before killing the jvm.


Any suggestions on how this can be acheived?


Michael Zamani

unread,
May 28, 2019, 10:03:32 PM5/28/19
to dropwizard-user
Hey there,

We also ran into this issue. A fix for this is included in https://github.com/dropwizard/dropwizard-health.

See the code/configs for delayedShutdownHandlerEnabled and shutdownWaitPeriod in particular.

Oscar Nalin

unread,
Jun 8, 2019, 10:32:08 AM6/8/19
to dropwizard-user

This is exactly what I was looking for!

 

I haven't used dropwizard modules before so not entirely sure how they work. There seems like there is only one version available on maven central: https://repo1.maven.org/maven2/io/dropwizard/modules/dropwizard-health/, which is on version 1.3.11-1, thus not the same version as latest dropwizard: https://repo1.maven.org/maven2/io/dropwizard/dropwizard-core/1.3.12/. Are the modules not a part of the normal release flow of Dropwizard?

Michael Zamani

unread,
Jun 8, 2019, 12:17:32 PM6/8/19
to dropwizard-user
Hey Oscar,

I wouldn’t worry about the version difference between the health module and Dropwizard. There shouldn’t be any incompatibilities that cause dropwizard-health not to work with the new patch version of dropwizard. You can make sure you’re still using dropwizard 1.3.12 by dependency managing to that version as well.
Reply all
Reply to author
Forward
0 new messages