-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
stub: use the closedTrailers in StatusException #12259
Conversation
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Fixes #12256
cc: @benjaminp