-
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: change serverimpl,servercallimpl's internalclose to cancel stream #4038
Changes from 4 commits
4787ccc
f64b5a4
4b99378
f08db82
6c54490
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import static io.grpc.internal.GrpcUtil.ACCEPT_ENCODING_SPLITTER; | ||
import static io.grpc.internal.GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY; | ||
import static io.grpc.internal.GrpcUtil.MESSAGE_ENCODING_KEY; | ||
import static java.lang.String.format; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.util.concurrent.MoreExecutors; | ||
|
@@ -37,6 +38,7 @@ | |
import io.grpc.ServerCall; | ||
import io.grpc.Status; | ||
import java.io.InputStream; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
final class ServerCallImpl<ReqT, RespT> extends ServerCall<ReqT, RespT> { | ||
|
@@ -205,7 +207,8 @@ public MethodDescriptor<ReqT, RespT> getMethodDescriptor() { | |
* on. | ||
*/ | ||
private void internalClose(Status internalError) { | ||
stream.close(internalError, new Metadata()); | ||
log.log(Level.WARNING,format("cancelling the stream with status %s",internalError.toString())); | ||
stream.cancel(internalError); | ||
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. 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. 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. ok. which level? Is 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. WARNING seems good. SEVERE seems a bit too much, because we were able to recover. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
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.
|
||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
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. Right now calling 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 |
||
assertNull(responseRef.get()); | ||
} | ||
} |
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.
Pass
internalError
as an argument and use MessageFormat-style syntax:We mainly use
String.format()
when we need to create a gRPC status description with an argument.