-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
core,netty: client sends rst stream when server half-closes #4222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,27 @@ | |
|
||
import com.google.common.base.Preconditions; | ||
import io.grpc.Status; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Command sent from a Netty client stream to the handler to cancel the stream. | ||
*/ | ||
class CancelClientStreamCommand extends WriteQueue.AbstractQueuedCommand { | ||
private final NettyClientStream.TransportState stream; | ||
private final Status reason; | ||
@Nullable private final Status reason; | ||
|
||
CancelClientStreamCommand(NettyClientStream.TransportState stream, Status reason) { | ||
this.stream = Preconditions.checkNotNull(stream, "stream"); | ||
Preconditions.checkNotNull(reason, "reason"); | ||
Preconditions.checkArgument(!reason.isOk(), "Should not cancel with OK status"); | ||
Preconditions.checkArgument( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im a little uncomfortable with using null here. I think a sentinel value like Status.CANCELED.withDescription("early trailers") would be a safer approach. Anything else that accesses the reason may expect it to be non null. Also, most of gRPC makes the status non null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of null here is to be able to send RST_STREAM to the server without invoking |
||
reason == null || !reason.isOk(), "Should not cancel with OK status"); | ||
this.reason = reason; | ||
} | ||
|
||
NettyClientStream.TransportState stream() { | ||
return stream; | ||
} | ||
|
||
@Nullable | ||
Status reason() { | ||
return reason; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,9 @@ public void deframeFailed(Throwable cause) { | |
|
||
void transportHeadersReceived(Http2Headers headers, boolean endOfStream) { | ||
if (endOfStream) { | ||
if (!isOutboundClosed()) { | ||
handler.getWriteQueue().enqueue(new CancelClientStreamCommand(this, null), true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do this after the The Status used here should probably make it obvious that it shouldn't be seen though. Maybe: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shoot. I am wrong. The second call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
transportTrailersReceived(Utils.convertTrailers(headers)); | ||
} else { | ||
transportHeadersReceived(Utils.convertHeaders(headers)); | ||
|
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.
I'd rather this conditional remain like it was (non-volatile). As it is written here, it seems like some other code path could
setOutboundClosed()
. However, it actually appears to be an unnecessary condition (halfClose is only called once), so let's instead leave it as you have it and do a follow-up PR to remove the condition.