Skip to content

Commit

Permalink
BugFix(stream): fix crash when peer send reset stream frame but has n…
Browse files Browse the repository at this point in the history
…o error message (#82)
  • Loading branch information
weimch authored Nov 21, 2023
1 parent 1f475f3 commit 0a23ad4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trpc/stream/trpc/trpc_client_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions trpc/stream/trpc/trpc_server_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0a23ad4

Please sign in to comment.