From be85da230c1d2e86e51275a2470da6971c122e27 Mon Sep 17 00:00:00 2001 From: weimch Date: Tue, 21 Nov 2023 11:54:56 +0800 Subject: [PATCH] BugFix(stream): fix crash when peer send reset stream frame but has no error message --- trpc/stream/trpc/trpc_client_stream.cc | 6 +++++- trpc/stream/trpc/trpc_server_stream.cc | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/trpc/stream/trpc/trpc_client_stream.cc b/trpc/stream/trpc/trpc_client_stream.cc index 09d29ab7..658d3eaf 100644 --- a/trpc/stream/trpc/trpc_client_stream.cc +++ b/trpc/stream/trpc/trpc_client_stream.cc @@ -336,8 +336,12 @@ RetCode TrpcClientStream::HandleClose(StreamRecvMessage&& msg) { // Close (RESET) due to an exception, so there is no need to check the stream status. // Notify the business that the stream has failed. SetState(State::kClosed); + if (status.OK()) { + // Normally, the reset frame will carry error code. But if it doesn't exist, we add an unknown error. + status.SetFrameworkRetCode(TrpcRetCode::TRPC_STREAM_UNKNOWN_ERR); + status.SetErrorMessage("stream reset recive, but unable to get error message"); + } OnError(status); - std::cout << "stream error occurs" << std::endl; return RetCode::kError; } diff --git a/trpc/stream/trpc/trpc_server_stream.cc b/trpc/stream/trpc/trpc_server_stream.cc index 6480ea06..6f84d0aa 100644 --- a/trpc/stream/trpc/trpc_server_stream.cc +++ b/trpc/stream/trpc/trpc_server_stream.cc @@ -175,6 +175,11 @@ RetCode TrpcServerStream::HandleClose(StreamRecvMessage&& msg) { if (reset) { // When closing (RESET) due to an exception, there is no need to check the stream state. SetState(State::kClosed); + if (status.OK()) { + // Normally, the reset frame will carry error code. But if it doesn't exist, we add an unknown error. + status.SetFrameworkRetCode(TrpcRetCode::TRPC_STREAM_UNKNOWN_ERR); + status.SetErrorMessage("stream reset recive, but unable to get error message"); + } OnError(status); return RetCode::kError; }