Skip to content

Commit be85da2

Browse files
committed
BugFix(stream): fix crash when peer send reset stream frame but has no error message
1 parent 1f475f3 commit be85da2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

trpc/stream/trpc/trpc_client_stream.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,12 @@ RetCode TrpcClientStream::HandleClose(StreamRecvMessage&& msg) {
336336
// Close (RESET) due to an exception, so there is no need to check the stream status.
337337
// Notify the business that the stream has failed.
338338
SetState(State::kClosed);
339+
if (status.OK()) {
340+
// Normally, the reset frame will carry error code. But if it doesn't exist, we add an unknown error.
341+
status.SetFrameworkRetCode(TrpcRetCode::TRPC_STREAM_UNKNOWN_ERR);
342+
status.SetErrorMessage("stream reset recive, but unable to get error message");
343+
}
339344
OnError(status);
340-
std::cout << "stream error occurs" << std::endl;
341345
return RetCode::kError;
342346
}
343347

trpc/stream/trpc/trpc_server_stream.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ RetCode TrpcServerStream::HandleClose(StreamRecvMessage&& msg) {
175175
if (reset) {
176176
// When closing (RESET) due to an exception, there is no need to check the stream state.
177177
SetState(State::kClosed);
178+
if (status.OK()) {
179+
// Normally, the reset frame will carry error code. But if it doesn't exist, we add an unknown error.
180+
status.SetFrameworkRetCode(TrpcRetCode::TRPC_STREAM_UNKNOWN_ERR);
181+
status.SetErrorMessage("stream reset recive, but unable to get error message");
182+
}
178183
OnError(status);
179184
return RetCode::kError;
180185
}

0 commit comments

Comments
 (0)