Skip to content

fix(storage): handle MRD hang corner case#14509

Merged
krishnamd-jkp merged 1 commit into
googleapis:release-storage-1.59.2from
krishnamd-jkp:mrd-hang
May 5, 2026
Merged

fix(storage): handle MRD hang corner case#14509
krishnamd-jkp merged 1 commit into
googleapis:release-storage-1.59.2from
krishnamd-jkp:mrd-hang

Conversation

@krishnamd-jkp

Copy link
Copy Markdown
Contributor

No description provided.

@krishnamd-jkp krishnamd-jkp requested a review from a team as a code owner April 30, 2026 17:49
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Apr 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a managerCtx to the bidiReadStreamSession to improve lifecycle management and prevent race conditions when sending results back to the manager. Key changes include refined error handling in the send and receive loops and explicit checks for context cancellation. Feedback was provided to ensure that databufs are consistently freed in all error paths of the receiveLoop to prevent memory leaks and to further guard against sending on closed channels.

Comment on lines +882 to 889
if s.managerCtx.Err() != nil {
return
}
select {
case s.respC <- result:
case <-s.ctx.Done():
case <-s.managerCtx.Done():
}
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In the error handling path of receiveLoop, databufs should be freed to avoid memory leaks. Additionally, to prevent sending on a closed channel (if the cancellation cleanup logic closes s.respC), explicitly check for context cancellation before the select block. This ensures that we do not attempt to send on s.respC if the context is already canceled, aligning with repository safety patterns.

			if s.managerCtx.Err() != nil {
				databufs.Free()
				return
			}
			select {
			case s.respC <- result:
			case <-s.managerCtx.Done():
			}
			databufs.Free()
			return
References
  1. To prevent sending on a closed channel, explicitly check for context cancellation before a select block that both sends on that channel and checks for the context's cancellation. This is necessary when the cancellation cleanup logic is responsible for closing the channel.

@krishnamd-jkp krishnamd-jkp requested a review from cpriti-os May 1, 2026 18:12
Comment thread storage/grpc_reader_multi_range.go
}
s.setError(err)

if s.managerCtx.Err() != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't this condition covered in the below select?
Same with line 904.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is in case of error. Once inside this if condition, the below block is not triggered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we are inside the switch statement when the error is thrown, could there still be a hang, this reduces the probability of it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh okay. Misread it. So I'm making sure if manager context is done, I don't still accidentally select the case s.respC <- result: case because that would lead to a panic if sent on a closed channel

@krishnamd-jkp krishnamd-jkp merged commit b3112f4 into googleapis:release-storage-1.59.2 May 5, 2026
8 checks passed
krishnamd-jkp added a commit that referenced this pull request May 14, 2026
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.12.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-go@sha256:718167d5c23ed389b41f617b3a00ac839bdd938a6bd2d48ae0c2f1fa51ab1c3d
<details><summary>storage: v1.59.3</summary>

##
[v1.59.3](storage/v1.59.2...storage/v1.59.3)
(2026-05-05)

### Bug Fixes

* handle MRD hang corner case (#14509)
([1ca3b6f](1ca3b6f0))

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants