actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Please add some way of closing HTTP/2 connections.

Open finnbear opened this issue 3 years ago • 0 comments

Expected Behavior

There should be some way of terminating ongoing HTTP/2 connections.

Current Behavior

Once an HTTP/2 connection has started, it will stay open even until closed by the client, the server stops, or (since recently) the underlying network connection closes.

Possible Solutions

  1. Request timeout. If an HTTP/2 connection goes X duration/Y pings without any request(s), it is closed. I know timers, due to the allocation they imply, are strictly rationed, but each HTTP/2 connection already has one (so it would technically be possible, with an integer counter, to use it for this purpose e.g. if 3 consecutive pings are sent without a request in between, terminate connection)
  2. HTTP Connection: close header. If I understand correctly, this is contrary to the HTTP/2 spec, but actix could catch it before it reaches the client and schedule the connection to be closed after any ongoing traffic finishes
  3. This is a bit extreme, but technically disabling HTTP/2 entirely would fix the issue (see Note and https://github.com/actix/actix-web/issues/1107)

Context

I have two servers, prod and staging. When I want to update my app, which consists of downloading a JS client over HTTP[/2] which opens a bincode WebSocket, I change the A record of my domain to point from the formerly-prod/newly-staging server to the formerly-staging/newly-prod server. However, every time this happens, there are many clients that maintain their HTTP/2 connection to the old server despite having updated their DNS settings, such that the old JS client opens WebSockets to the new server. Due to protocol incompatibility, these clients crash. Making matters worse, refreshing the page won't solve the problem (as the HTTP/2 connection still remains open). I don't know of any way, via JavaScript, to tell the browser to close the connection. So, until I forcefully shut down the old server, many users experience a bricked page.

Note

Many use cases benefit from long-running HTTP/2 connections. However, my use case does not because it is a single-page app that makes all its non-WebSocket requests in the first few hundreds of milliseconds. After that, the connection's only purpose to remain open would be to make refreshing the single page faster, but users have no incentive to refresh the page (with the minor exception of changing a graphics setting).

Your Environment

  • Actix Web Version: 4.0.0-beta.14

finnbear avatar Dec 12 '21 19:12 finnbear