Ref https://gist.github.com/aaronjensen/33cc2aeb74746cac3bcb40dcefdd9c09
We'd need to make this part of the behavior that can be optionally supported by adapters, and it's also worth considering as part of plug.
Given that ranch is OTP compliant we can just specify a shutdown option for the child specification of the connection supervisor in Ranch. This will follow standard shutdown behavior, :infinity isn't the best idea for graceful shutdown of workers but a user-specified wait time would suffice.
My understanding is that when shutting down the ranch_cons_sup sends an exit signal to its children which, as I understand it, if the children are not trapping exists, they will be killed immediately. In other words, you have to actually wait for the children to die themselves. Maybe I'm misunderstanding something though.
I'm not sure where the mention of :infinity is coming from, the gist has an explicit timeout that defaults to 5000.
Yes, if you are not trapping exits then you cannot depend on ranch's graceful shutdown which follows normal OTP behavior.
Your workaround is required because of these points.
We are going to hold on this one and for now the best solution is to release it as a separate package for those that need it. Because it requires trapping exits of all requests, we feel the tradeoffs need to be carefully considered so it's not something that should be in core. Thanks!
Ok, sounds good. For what it's worth, it doesn't actually require trapping exits of all requests if you want to do it in the way that I did it, which seems to work just fine even if it's not the most "clean" thing in the world.
Maybe this small package will help someone trying to get connection draining working in Phoenix.
Most helpful comment
Maybe this small package will help someone trying to get connection draining working in Phoenix.