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

netty: Eliminate buffer release when there is an error as caller still owns the buffer. #10537

Merged
merged 6 commits into from Sep 15, 2023

Conversation

larry-safran
Copy link
Contributor

Fixes #10255

Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

I don't think this is right. I was very thorough working on this code. This change contradicts the comments in the test:

// Input must be released unless its ownership has been to the composite cumulation.
assertEquals(1, in.refCnt());

Not releasing input buffer in finally is dangerous.
I need more time to look at the reported issue and understand the consequences of this change.

… that fails then the operation hasn't completed correctly and the ownership of the buffer should remain with the caller.
@larry-safran
Copy link
Contributor Author

@sergiitk after our discussion yesterday are you now okay with this?

@@ -582,6 +583,7 @@ public CompositeByteBuf addFlattenedComponents(boolean increaseWriterIndex,
assertEquals(0, compositeRo.numComponents());
} finally {
compositeRo.release();
in.release();
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep it abovefail("Cumulator didn't throw");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to release when there is an error since the new paradigm is that only successes change ownership.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed IRL, we do want to move it, but to another place

@@ -546,6 +546,7 @@ public CompositeByteBuf addFlattenedComponents(boolean increaseWriterIndex,
assertEquals(0, compositeThrows.numComponents());
} finally {
compositeThrows.release();
in.release();
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep it abovefail("Cumulator didn't throw");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is expected the in the case of an error that the ownership remained with the calling method so it is this method's responsibility to do the release.

Co-authored-by: Sergii Tkachenko <hi@sergii.org>
Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

Awesome! Thank you so much for catching this!

@larry-safran larry-safran merged commit 6f09466 into grpc:master Sep 15, 2023
13 of 14 checks passed
@larry-safran larry-safran deleted the is10255 branch September 15, 2023 22:18
DNVindhya pushed a commit to DNVindhya/grpc-java that referenced this pull request Oct 5, 2023
…l owns the buffer. (grpc#10537)

* netty: Eliminate buffer release when there is an error as caller still owns the buffer.
---------

Co-authored-by: Sergii Tkachenko <hi@sergii.org>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NettyAdaptiveCumulator incorrectly releases ByteBuf in twice
2 participants