Graceful drain connections in WebClient/HttpClient

190 views
Skip to first unread message

Tom Fingerman

unread,
Jul 7, 2021, 5:04:27 AM7/7/21
to vert.x
I have a use case where the HTTP server i connect to has a very primitive load balancer in front of it.

When one of the proxied servers is about to go down - usually for maintenance, they fire a command to the load balancer to stop moving traffic to the proxied server that is going down, but it does not affect existing opened sockets (http 1.1 sticky sessions).

It would be great if i could somehow "tell" vertx web client to gracefully drain existing connections without harming in-transit requests.

The full scenario would be:
1. The HTTP server's team decide to take one of the proxied server down
2. The HTTP server's team instruct their load balancer to stop proxy connections to one of hte proxied server
3. I instruct the web client to drain all existing connections gracefully, new connections will open against a valid server because the load balancer will not open connections to the proxied server that should go down
4. the HTTP server's team can take the target proxy server down for maintenance without harming existing trafic

I was also thinking of implementing something by myself but i could not get the actual connection in an interceptor from io.vertx.ext.web.client.impl.HttpContext

Julien Viet

unread,
Jul 7, 2021, 4:28:56 PM7/7/21
to vert.x
Hi,

one way to achieve that would be to use HTTP/2 which has exactly the
tools for this.

Here is how it could work:

1/ the HTTP server team tells the proxy to route to the new HTTP server
2/ the original HTTP server performs a shutdown of the connections
with a timeout (e.g in Vert.x you can use
HttpConnection#shutdown(timeout)) and it will send an HTTP/2 GO_AWAY
frame
3/ the WebClient will then receive the GO_AWAY frame for each
connection and will shut them down, i.e they will not be used anymore
(i.e removed from the pool)

Otherwise it will be somehow complicated because the HTTP client will
not be aware of this and will continue to use the connection from the
pool. In this situation each connection to the proxies server could be
shutdown with HttpConnection#shutdown that takes the connection out of
the pool for HTTP/1.

You can maintain a Map<Host, List<HttpConnection>> with
HttpClient#connectionHandler and HttpConnection#closeHandler and then
use this data structure to shutdown the connection you need for a
given host.

HTH

Julien
> --
> You received this message because you are subscribed to the Google Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/9f59ac72-be7e-4bbd-8f19-81f459611a3en%40googlegroups.com.

Tom Fingerman

unread,
Jul 8, 2021, 2:38:54 AM7/8/21
to vert.x
Hi Julien,

Thanks for the response :)

As i can't force the other side to work with http/2 i will probably go toward something close to what you suggested.

Thanks!
Reply all
Reply to author
Forward
0 new messages