-
Notifications
You must be signed in to change notification settings - Fork 8
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
Handle Connection: close response from server #211
Conversation
A server may return `Connection: close` while gracefully shutting down. Mint will mark the connection state as closed and return the response from the server (NOTE: it will not return any error). Since the client doesn't know the connection is closed, it will try to use the connection for the next request and will fail. Before making any HTTP request, check the internal state of the connection and attempt to reconnect once if necessary. partially related to plausible#210
2fec2a7
to
11d67ef
Compare
Thank you for the contribution! I had my doubts about re-connecting outside of DBConnection lifecycle, but this looks very clean and I think is the way to go! |
@ruslandoga btw, to be clear, this will only work if the server uses |
Or maybe https://www.erlang.org/doc/apps/kernel/inet.html#monitor/1 and whatever is :ssl's alternative could work? I wonder where the messages would be received and how it would even work with the DBConnection's checkout mechanism. I guess, if we monitor the socket in |
I haven't looked into the general case issue. I added graceful shutdown to our clickhouse proxy and realized the client is still failing once. This fix will gracefully handle the connection: close. For the general case, I think DBConnection ping already acts like a socket monitor and reconnects in case of timeout, etc. We could definitely improve the detection time, but that would require much more effort, as you noted, it seems like DBConnection controls the process and the callback can't have a separate message queue, etc. I initially attempted to use |
Ah, I see. I just wanted to recommend that :) It would've been nice to reconnect right after the "last" |
Thank you again for the contribution! I wonder if you'd like me to make another release (btw, do you think it warrants a version bump to v0.3.0?) or if we can sit on it for a bit until we come up with a more general fix for closed connections? |
Actually, can we do it with the same logic as in this PR right after |
give me some time, let me test this out on our staging |
Btw, I opened an issue on DBConnection asking for guidance: elixir-ecto/db_connection#315 |
I have tested it a bit, and the connection: close problem looks like solved. I still see a few Mint.TransportError, but it might be something else.
Release can be delayed, no issue from my side. |
A server may return
Connection: close
while gracefully shutting down. Mint will mark the connection state as closed and return the response from the server (NOTE: it will not return any error). Since the client doesn't know the connection is closed, it will try to use the connection for the next request and will fail.Before making any HTTP request, check the internal state of the connection and attempt to reconnect once if necessary.
partially related to #210