Skip to content

Commit 85fec25

Browse files
committed
fix grpc: call Finish even when Rpc interrrupted
есть такое, правда оно к callback API относится: <https://grpc.io/docs/languages/cpp/best_practices/> """ 18\. Does server still need to call `Finish` if `OnCancel` is run? Yes, although the status passed to `Finish` is ignored. """ пример тоже по callback API <https://github.com/grpc/grpc/blob/d1842f693085db8c66b84d368e4aa3b9357eee1a/examples/cpp/cancellation/server.cc#L54> """ не может быть такое, что какие-то внутренние ресурсы grpc-core продолжают висеть пока явно Finish не позовем? ~~и OnDone возможно чуть раньше прилетит~~ """ commit_hash:8b292a764e63795a887575c76e9e4b33a177dbad
1 parent 9f56219 commit 85fec25

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

grpc/include/userver/ugrpc/server/impl/call_processor.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void UnpackResult(StreamingResult<Response>&& result, std::optional<Response>& r
6666
}
6767

6868
template <typename CallTraits>
69-
bool Finish(
69+
[[nodiscard]] bool Finish(
7070
impl::Responder<CallTraits>& responder,
7171
const std::optional<typename CallTraits::Response>& response,
7272
grpc::Status& status
@@ -87,6 +87,12 @@ bool Finish(
8787
}
8888
}
8989

90+
template <typename CallTraits>
91+
void FinishInterrupted(impl::Responder<CallTraits>& responder) {
92+
grpc::Status status{grpc::Status::CANCELLED};
93+
[[maybe_unused]] const bool ok = responder.FinishWithError(status);
94+
}
95+
9096
template <typename CallTraits>
9197
class CallProcessor final {
9298
public:
@@ -137,9 +143,12 @@ class CallProcessor final {
137143
if (!engine::current_task::ShouldCancel() && !responder_.IsInterrupted()) {
138144
RunPreFinishHooks(response);
139145
finished = impl::Finish(responder_, response, status_);
140-
scope_time.Reset("post_finish");
146+
} else {
147+
impl::FinishInterrupted(responder_);
141148
}
142149

150+
scope_time.Reset("post_finish");
151+
143152
if (finished) {
144153
impl::ReportFinished(status_, state_);
145154
} else {

0 commit comments

Comments
 (0)