Skip to content

Commit

Permalink
[Documentation] Update docs for TryCancel() on ServerContext (#32889)
Browse files Browse the repository at this point in the history
Fix #32638

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
  • Loading branch information
yashykt authored and wanlin31 committed May 18, 2023
1 parent ed3a795 commit 59328a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/grpcpp/server_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class ServerContextBase {
/// TryCancel() is called, the serverhandler must return Status::CANCELLED.
/// The only exception is that if the serverhandler is already returning an
/// error status code, it is ok to not return Status::CANCELLED even if
/// TryCancel() was called.
/// TryCancel() was called. Additionally, it is illegal to invoke TryCancel()
/// before the call has actually begun, i.e., before metadata has been
/// received from the client.
///
/// For reasons such as the above, it is generally preferred to explicitly
/// finish an RPC by returning Status::CANCELLED rather than using TryCancel.
Expand Down
8 changes: 7 additions & 1 deletion src/core/lib/surface/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,9 @@ grpc_call* grpc_call_from_top_element(grpc_call_element* surface_element) {
grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) {
GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved));
GPR_ASSERT(reserved == nullptr);
if (call == nullptr) {
return GRPC_CALL_ERROR;
}
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx;
grpc_core::Call::FromC(call)->CancelWithError(absl::CancelledError());
Expand All @@ -3536,6 +3539,9 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c,
"c=%p, status=%d, description=%s, reserved=%p)",
4, (c, (int)status, description, reserved));
GPR_ASSERT(reserved == nullptr);
if (c == nullptr) {
return GRPC_CALL_ERROR;
}
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx;
grpc_core::Call::FromC(c)->CancelWithStatus(status, description);
Expand Down Expand Up @@ -3576,7 +3582,7 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops,
"reserved=%p)",
5, (call, ops, (unsigned long)nops, tag, reserved));

if (reserved != nullptr) {
if (reserved != nullptr || call == nullptr) {
return GRPC_CALL_ERROR;
} else {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
Expand Down

0 comments on commit 59328a5

Please sign in to comment.