Skip to content
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

Fix buffer leak regression in HttpClientCodec #12762

Merged
merged 1 commit into from
Sep 1, 2022

Conversation

yawkat
Copy link
Contributor

@yawkat yawkat commented Sep 1, 2022

Motivation:

#12709 changed HttpObjectEncoder to override the write method of MessageToMessageEncoder, with slightly changed semantics: The msg argument to encode is not released anymore. To accommodate this change, #12709 also update HttpObjectEncoder.encode to release the msg. However, HttpClientCodec.Encoder overrides encode and simply forwards the message if a HTTP upgrade has been completed. This code path was not updated to release the input message. This leads to a memory leak.

Modifications:

Changed the encode implementation to not retain the message that is forwarded. Added a test case to verify that the refCnt to the data passed through is unchanged.

Result:

The buffer retains its correct refCnt and will be released properly.

Motivation:

netty#12709 changed HttpObjectEncoder to override the write method of MessageToMessageEncoder, with slightly changed semantics: The `msg` argument to `encode` is not released anymore. To accommodate this change, netty#12709 also update `HttpObjectEncoder.encode` to release the `msg`. However, `HttpClientCodec.Encoder` overrides `encode` and simply forwards the message if a HTTP upgrade has been completed. This code path was not updated to release the input message. This leads to a memory leak.

Modifications:

Changed the `encode` implementation to not retain the message that is forwarded. Added a test case to verify that the refCnt to the data passed through is unchanged.

Result:

The buffer retains its correct refCnt and will be released properly.
Copy link
Contributor

@chrisvest chrisvest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@chrisvest chrisvest added this to the 4.1.81.Final milestone Sep 1, 2022
@franz1981
Copy link
Contributor

franz1981 commented Sep 1, 2022

Please @yawkat separately, can you update the scalability issue in case you have performance regressions (or, as expected, improvements) due to #12709?

And thanks to adding that test :)

@yawkat
Copy link
Contributor Author

yawkat commented Sep 1, 2022

We don't really have benchmarks that could tell the difference unfortunately

@normanmaurer normanmaurer merged commit 05943f5 into netty:4.1 Sep 1, 2022
@slandelle
Copy link
Contributor

Hi there,

From my understanding, 4.1.80 is basically burnt because of this regression.
What are the plans for the 4.1.81 release date? I'm trying to figure out if we should revert to 4.1.79, fork the fix or wait for the release.

Cheers!

@normanmaurer
Copy link
Member

release should happen within the next days.

@slandelle
Copy link
Contributor

Awesome! Thanks a lot @normanmaurer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants