Overview
I am working on a Netty-powered HTTP2 proxy, meaning that the server will accept HTTP2 frames and forward them on to an outbound 'node', receiving the responses and sending them back to the original 'client'. Until a GOAWAY frame is received, you would expect just a single inbound TCP connection (from the client) and a single outbound TCP connection (to the node) to be open. Hopefully that makes sense, but since a picture is worth 1,000 words etc:

Expected behavior
On the client (outbound) flow - which is #2/#3 in the diagram above - I would have expected there to be a way for the established TCP connection to be kept open until a GOAWAY frame is received, so that all HTTP2 frames across multiple streamIds will be sendable through the same TCP connection.
Actual behavior (summary)
I have been unable to find a way of doing this (keeping the connection open). DefaultHttp2ConnectionDecoder does the following:
if (endOfStream) {
lifecycleManager.closeStreamRemote(stream, ctx.newSucceededFuture());
}
meaning that once our outbound-established connection receives a HEADER or DATA frame which is marked as end of stream, the connection is closed. Therefore if there is a subsequent HEADER or DATA inbound frame from the client (for a different streamId), attempting to write this to the outbound node will result in a ClosedChannelException.
In other words:
- A HTTP2 request comes in for
/test (Build stability fix + .gitignore update #1 in the earlier diagram)
- This will be forwarded on (Typo fixes #2), and the HTTP2 response (Add a new faster, memory efficient URL decoder. #3) is HTML which contains some assets (css/images etc). At this point, the outbound TCP connection (established during Typo fixes #2) is closed by Netty.
- The response is sent back to the client (Fix for NETTY-370 #4) via the original inbound TCP connection.
- The client sees that there are assets, and sends
HEADER frames up (Build stability fix + .gitignore update #1) - with different streamIds - for these. Trying to write these to the outbound (Typo fixes #2) fails with ClosedChannelException because Netty closed the connection earlier.
Code/further explanation
Because of the issue explained above, I am currently creating a new Http2StreamChannel for each new outbound connection - code for this is on a previous Stackoverflow question I asked.
Creating a new connection/Http2StreamChannel naturally works around the original issue, however it obviously means the proxy isn't as efficient because many TCP connections are opened/closed on the outbound.
So I'm guessing that either:
- My linked code on SO is wrong and I'm creating new connections when there is an alternative/better way of approaching this
or:
- There needs to be a way of keeping
Http2MultiplexCodec/Http2FrameCodec-powered connections open even after an end of stream frame is received?