Skip to content

stub: use the closedTrailers in StatusException #12259

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

Merged
merged 3 commits into from
Aug 6, 2025

Conversation

shivaspeaks
Copy link
Member

Fixes #12256

cc: @benjaminp

@@ -128,7 +129,7 @@ private RespT read(boolean waitForever, long endNanoTime)
throw new IllegalStateException(
"The message disappeared... are you reading from multiple threads?");
} else if (!currentClosedStatus.isOk()) {
throw currentClosedStatus.asException();
throw currentClosedStatus.asException(closedTrailers);
Copy link
Contributor

Choose a reason for hiding this comment

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

We are assigning member currentStatus variable to local variable currentClosedStatus everywhere because another thread can change it value and there is no synchronisation in our code. Similar concern will apply to metadata trailers as well. In addition we need to ensure that currentStatus and closedTrailers are ready as an atomic whole.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we use something like Pair to contain both status and metadata and call it volatile?

Preconditions.checkState(closedStatus == null, "ClientCall already closed");
closedStatus = status;
CloseState newCloseState = new CloseState(status, trailers);
boolean wasSet = closeState.compareAndSet(null, newCloseState);
Copy link
Member

Choose a reason for hiding this comment

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

This is the only place assigning the value, so the code was fine with a plain volatile. It only runs on one thread. The volatile is because it is read by other threads, but it is read-only.

final Metadata trailers;

CloseState(Status status, Metadata trailers) {
this.status = status;
Copy link
Member

Choose a reason for hiding this comment

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

Let's have a checkNotNull here, for clarity.

@shivaspeaks shivaspeaks merged commit 7040417 into grpc:master Aug 6, 2025
15 of 16 checks passed
@shivaspeaks shivaspeaks deleted the include-trailers-in-exception branch August 6, 2025 06:54
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.

BlockingClientCall drops trailers
3 participants