-
Notifications
You must be signed in to change notification settings - Fork 4k
stub: ignore unary response msg if status is not OK for async server #6296
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -314,6 +314,7 @@ private static final class ServerCallStreamObserverImpl<ReqT, RespT> | |
| private Runnable onCancelHandler; | ||
| private boolean aborted = false; | ||
| private boolean completed = false; | ||
| private RespT unaryResponse; | ||
|
|
||
| // Non private to avoid synthetic class | ||
| ServerCallStreamObserverImpl(ServerCall<ReqT, RespT> call) { | ||
|
|
@@ -348,7 +349,13 @@ public void onNext(RespT response) { | |
| call.sendHeaders(new Metadata()); | ||
| sentHeaders = true; | ||
| } | ||
| call.sendMessage(response); | ||
|
|
||
| if (!call.getMethodDescriptor().getType().serverSendsOneMessage()) { | ||
| call.sendMessage(response); | ||
| } else { | ||
| // delay the sendMessage() to onComplete()/onError() | ||
| unaryResponse = response; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -368,8 +375,28 @@ public void onCompleted() { | |
| throw Status.CANCELLED.withDescription("call already cancelled").asRuntimeException(); | ||
| } | ||
| } else { | ||
| call.close(Status.OK, new Metadata()); | ||
| completed = true; | ||
|
|
||
| if (call.getMethodDescriptor().getType().serverSendsOneMessage()) { | ||
| Throwable error = null; | ||
|
Contributor
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 error should be logged to the server log. |
||
| if (unaryResponse != null) { | ||
| try { | ||
| call.sendMessage(unaryResponse); | ||
| } catch (Throwable t) { | ||
| error = t; | ||
| } | ||
| } else { | ||
| error = Status.INTERNAL.withDescription("Response message is null for unary call") | ||
| .asRuntimeException(); | ||
| } | ||
| if (error != null) { | ||
| onError(error); | ||
|
Member
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 error is sent to the client. We should not send either of the two possible What we should do instead is slightly unclear, but we can talk about it offline. |
||
| } | ||
| } | ||
|
|
||
| if (!aborted) { | ||
| call.close(Status.OK, new Metadata()); | ||
| completed = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
IMO this should throw an exception if the server sends multiple responses/overwrites the previous one.