Nothing Special   »   [go: up one dir, main page]

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(pubsub): close grpc streams on retry #10624

Merged
merged 7 commits into from
Sep 5, 2024

Conversation

itizir
Copy link
Contributor
@itizir itizir commented Aug 1, 2024

Following up on #10094 and #10153: even after deploying with the fix that was merged, we continued seeing similar leaks in some conditions. We eventually realised that the reason was that the retry logic in pullStream meant grpc streams could still escape the closing mechanism that was added in #10153.

Submitting this little PR with a suggestion on how to prevent such leaks.

follow-up as 66581c4 is not enough to
plug all stream leaks
@itizir itizir requested review from shollyman and a team as code owners August 1, 2024 13:33
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Aug 1, 2024
@shollyman shollyman requested a review from hongalex August 9, 2024 21:59
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 9, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 9, 2024
@@ -100,29 +103,33 @@ func (s *pullStream) get(spc *pb.Subscriber_StreamingPullClient) (*pb.Subscriber
if spc != s.spc {
return s.spc, nil
}
// we are about to open a new stream: if necessary, make sure the previous one is closed
if s.close != nil {
s.close()
Copy link
Member

Choose a reason for hiding this comment

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

So if I'm reading this correctly, there's a desire to make sure the stream is closed, both here and in line 74 above. Why can't you call pullstream.cancel instead? Could you explain a bit more why an additional cancel func is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! So on L74 it's just to tidy up the context that's just been created rather than actually close the stream (since the stream creation would have errored out).

But an additional context and separate, corresponding cancel function are needed because the main pullStream ctx and cancel are meant to last for the whole lifecycle of pullStream, while the grpc streams that are leaked may have a shorter lifespan (precisely because of the retry, when you get back here on L115 after the initial stream creation), so need to be tied to a shorter-lived child context of the main pullStream one.

Copy link
Member

Choose a reason for hiding this comment

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

Ack, yeah that makes sense. I'll approve and prioritize merging this week. Thanks for the contribution!

Copy link

Choose a reason for hiding this comment

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

Is there something I can help out with to get this into the next release? Suffering from the same memory leak as @itizir 🙏

@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 12, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 12, 2024
@hongalex hongalex enabled auto-merge (squash) August 19, 2024 19:01
@hongalex hongalex disabled auto-merge August 19, 2024 22:22
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Sep 5, 2024
@hongalex hongalex enabled auto-merge (squash) September 5, 2024 22:42
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Sep 5, 2024
@hongalex hongalex merged commit 79a0e11 into googleapis:main Sep 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants