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

core: change serverimpl,servercallimpl's internalclose to cancel stream #4038

Merged
merged 5 commits into from
Feb 22, 2018

Conversation

ramaraochavali
Copy link
Contributor

Signed-off-by: Rama [email protected]
Fixes #3819, #3746

@zhangkun83 zhangkun83 requested a review from ejona86 February 7, 2018 18:45
@@ -205,7 +205,7 @@ public String getAuthority() {
* on.
*/
private void internalClose(Status internalError) {
stream.close(internalError, new Metadata());
stream.cancel(internalError);
Copy link
Member

Choose a reason for hiding this comment

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

This status is stored internally in gRPC, but won't actually be exposed anywhere on server-side. We should probably go ahead and log it here.

Copy link
Contributor Author

@ramaraochavali ramaraochavali Feb 16, 2018

Choose a reason for hiding this comment

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

ok. which level? Is SEVERE the correct level? I have added with WARN. Let me know if needs to be changed.

Copy link
Member

Choose a reason for hiding this comment

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

WARNING seems good. SEVERE seems a bit too much, because we were able to recover.

@@ -247,7 +247,7 @@ public void onCompleted() {
.onNext(StreamingInputCallRequest.getDefaultInstance());

assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(Status.UNKNOWN, Status.fromThrowable(throwableRef.get()));
assertEquals(Status.CANCELLED.getCode(), Status.fromThrowable(throwableRef.get()).getCode());
Copy link
Member

Choose a reason for hiding this comment

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

Right now calling serverStream.cancel() will propagate a CANCEL HTTP/2 error to the remote. It'd probably be better if it was INTERNAL_ERROR, which will get mapped to a INTERNAL grpc status code. That way the client would get a signal that it shouldn't retry.

I think it'd be fair to map gRPC's DEADLINE_EXCEEDED and CANCELLED error codes to HTTP/2's CANCEL, and everything else map to HTTP/2's INTERNAL_ERROR. Right now we use DEADLINE_EXCEEDED for when deadline expires. That mapping could be in NettyServerHandler.cancelStream().

@@ -610,8 +610,7 @@ void setListener(ServerStreamListener listener) {
* Like {@link ServerCall#close(Status, Metadata)}, but thread-safe for internal use.
*/
private void internalClose() {
// TODO(ejona86): this is not thread-safe :)
stream.close(Status.UNKNOWN, new Metadata());
stream.cancel(Status.INTERNAL);
Copy link
Member

Choose a reason for hiding this comment

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

Fix doc comments if you change? edit: Please don't care.

@ramaraochavali
Copy link
Contributor Author

@ejona86 addressed the comments, PTAL and let me know if any further changes are needed.

@@ -205,7 +207,8 @@ public String getAuthority() {
* on.
*/
private void internalClose(Status internalError) {
stream.close(internalError, new Metadata());
log.log(Level.WARNING,format("cancelling the stream with status %s",internalError.toString()));
Copy link
Member

Choose a reason for hiding this comment

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

Pass internalError as an argument and use MessageFormat-style syntax:

log.log(Level.WARNING, "Cancelling the stream with status {0}", new Object[] {internalError});

We mainly use String.format() when we need to create a gRPC status description with an argument.

@ejona86
Copy link
Member

ejona86 commented Feb 20, 2018

One small change, and then I can merge.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Feb 20, 2018
@kokoro-team kokoro-team removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Feb 20, 2018
@ramaraochavali
Copy link
Contributor Author

@ejona86 changed. PTAL.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Feb 21, 2018
@kokoro-team kokoro-team removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Feb 21, 2018
@ejona86 ejona86 requested a review from zpencer February 21, 2018 16:38
@zpencer zpencer merged commit 48ca452 into grpc:master Feb 22, 2018
@ramaraochavali ramaraochavali deleted the fix/stream_close branch February 23, 2018 06:12
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Mar 2, 2018
…ose to cancel stream (grpc#4038)"

This partially reverts commit 48ca452.
It leaves the changes to ServerCallImpl and test.

This also partially reverts "Lint fixes" commit
3002a23 which removed unused variables
which are now necessary again.
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Mar 2, 2018
…ose to cancel stream (grpc#4038)"

This partially reverts commit 48ca452.
It leaves the changes to ServerCallImpl and test.

This also partially reverts "Lint fixes" commit
3002a23 which removed unused variables
which are now necessary again.

This is reverted for the combined result of two issues:
* Some users are testing that they get UNKNOWN when the service throws.
  That's not unreasonable given the behavior was well-publicised when it
  changed in v1.5. We should probably keep the UNKNOWN in some common
  cases (like the service threw immediately, before sending anything).
* The client always saw CANCELLED, not INTERNAL as had been intended.
  This is behavior is visible in the tests and was overlooked during
  reveiw.
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Mar 2, 2018
…ose to cancel stream (grpc#4038)"

This partially reverts commit 48ca452.
It leaves the changes to ServerCallImpl and test.

This also partially reverts "Lint fixes" commit
3002a23 which removed unused variables
which are now necessary again.

This is reverted for the combined result of two issues:
* Some users are testing that they get UNKNOWN when the service throws.
  That's not unreasonable given the behavior was well-publicised when it
  changed in v1.5. We should probably keep the UNKNOWN in some common
  cases (like the service threw immediately, before sending anything).
* The client always saw CANCELLED, not INTERNAL as had been intended.
  This is behavior is visible in the tests and was overlooked during
  review.
ejona86 added a commit to ejona86/grpc-java that referenced this pull request Mar 2, 2018
…ose to cancel stream (grpc#4038)"

This partially reverts commit 48ca452.
It leaves the changes to ServerCallImpl and test.

This also partially reverts "Lint fixes" commit
3002a23 which removed unused variables
which are now necessary again.

This is reverted for the combined result of two issues:
* Some users are testing that they get UNKNOWN when the service throws.
  That's not unreasonable given the behavior was well-publicised when it
  changed in v1.5. We should probably keep the UNKNOWN in some common
  cases (like the service threw immediately, before sending anything).
* The client could see CANCELLED instead of INTERNAL as had been
  intended. It's unclear as to why (I didn't investigate heavily). This
  behavior is visible in MoreInProcessTest and was overlooked during
  review.
ejona86 added a commit that referenced this pull request Mar 2, 2018
…ose to cancel stream (#4038)"

This partially reverts commit 48ca452.
It leaves the changes to ServerCallImpl and test.

This also partially reverts "Lint fixes" commit
3002a23 which removed unused variables
which are now necessary again.

This is reverted for the combined result of two issues:
* Some users are testing that they get UNKNOWN when the service throws.
  That's not unreasonable given the behavior was well-publicised when it
  changed in v1.5. We should probably keep the UNKNOWN in some common
  cases (like the service threw immediately, before sending anything).
* The client could see CANCELLED instead of INTERNAL as had been
  intended. It's unclear as to why (I didn't investigate heavily). This
  behavior is visible in MoreInProcessTest and was overlooked during
  review.
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants