HTTP/2: Prevent memory leak when trying to create new streams on a connection that received a GOAWAY.#9674
Conversation
…nnection that received a GOAWAY. Motivation: In netty#8692, `Http2FrameCodec` was updated to keep track of all "being initialized" streams, allocating memory before initialization begins, and releasing memory after initialization completes successfully. In some instances where stream initialization fails (e.g. because this connection has received a GOAWAY frame), this memory is never released. Modifications: This change updates the `Http2FrameCodec` to use a separate promise for monitoring the success of sending HTTP2 headers. When sending of headers fails, we now make sure to release memory allocated for stream initialization. Result: After this change, failures in writing HTTP2 Headers (e.g. because this connection has received a GOAWAY frame) will no longer leak memory.
|
Can one of the admins verify this patch? |
normanmaurer
left a comment
There was a problem hiding this comment.
A few nits but generally LGTM!
codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java
Outdated
Show resolved
Hide resolved
codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java
Outdated
Show resolved
Hide resolved
codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java
Outdated
Show resolved
Hide resolved
codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java
Show resolved
Hide resolved
|
@millems can you please also sign our icla: https://netty.io/s/icla |
|
@netty-bot test this please |
|
@millems probably I'm missing something but why is a separate promise needed? Couldn't we just add a listener to the existing promise? |
|
@njhill Using a separate promise was intended to be defensive, and only performing the cleanup if the send-headers failed. I was concerned about the following scenario:
Let me know if this concern is unfounded, and I can remove the additional future. |
|
@normanmaurer Will review comments and address. CLA was reviewed and signed yesterday. Let me know if it's not on record and I can go again. |
|
@millems all good... I somehow missed it 🤦♂ |
1. Assert channel.finishAndReleaseAll() returns false. 2. Attach failure detection to original future, instead of a separate future. 3. Use ChannelListener instead of GenericFutureListener 4. Note that numInitializingStreams is for testing.
|
Addressed change requests. |
codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java
Outdated
Show resolved
Hide resolved
|
@netty-bot test this please |
|
@netty-bot test this please |
normanmaurer
left a comment
There was a problem hiding this comment.
@millems thanks a lot for your work... :)
…nnection that received a GOAWAY. (#9674) Motivation: In #8692, `Http2FrameCodec` was updated to keep track of all "being initialized" streams, allocating memory before initialization begins, and releasing memory after initialization completes successfully. In some instances where stream initialization fails (e.g. because this connection has received a GOAWAY frame), this memory is never released. Modifications: This change updates the `Http2FrameCodec` to use a separate promise for monitoring the success of sending HTTP2 headers. When sending of headers fails, we now make sure to release memory allocated for stream initialization. Result: After this change, failures in writing HTTP2 Headers (e.g. because this connection has received a GOAWAY frame) will no longer leak memory.
Motivation:
In #8692,
Http2FrameCodecwas updated to keep track of all "being initialized" streams, allocating memory before initialization begins, and releasing memory after initialization completes successfully.In some instances where stream initialization fails (e.g. because this connection has received a GOAWAY frame), this memory is never released.
Modifications:
This change updates the
Http2FrameCodecto use a separate promise for monitoring the success of sending HTTP2 headers. When sending of headers fails, we now make sure to release memory allocated for stream initialization.Result:
After this change, failures in writing HTTP2 Headers (e.g. because this connection has received a GOAWAY frame) will no longer leak memory.