Skip to content

Commit bdab7e2

Browse files
committed
bug grpc: fix a rare data race in client::ReaderWriter with parallel read-write
commit_hash:1cc8c1961246741ebfd96ce094ad97160a0a58e7
1 parent a232f29 commit bdab7e2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

grpc/include/userver/ugrpc/client/impl/async_stream_methods.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool Write(GrpcStream& stream, const Request& request, grpc::WriteOptions option
150150
const auto lock = state.TakeMutexIfBidirectional();
151151
if (state.IsFinished()) {
152152
// It't forbidden to work with a stream after Finish.
153-
throw ugrpc::client::RpcInterruptedError{state.GetCallName(), "Write"};
153+
return false;
154154
}
155155

156156
UINVARIANT(IsWriteAvailable(state), "'impl::Write' called on a stream that is closed for writes");

grpc/include/userver/ugrpc/client/impl/rpc.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ bool BidirectionalStream<Request, Response>::Write(const Request& request) {
427427

428428
{
429429
const auto lock = state_.TakeMutexIfBidirectional();
430+
if (state_.IsFinished()) {
431+
// It't forbidden to work with a stream after Finish.
432+
return false;
433+
}
430434
RunMiddlewarePipeline(state_, MiddlewareHooks::SendMessageHooks(request));
431435
}
432436

@@ -445,6 +449,10 @@ void BidirectionalStream<Request, Response>::WriteAndCheck(const Request& reques
445449

446450
{
447451
const auto lock = state_.TakeMutexIfBidirectional();
452+
if (state_.IsFinished()) {
453+
// It't forbidden to work with a stream after Finish.
454+
throw ugrpc::client::RpcInterruptedError{state_.GetCallName(), "WriteAndCheck"};
455+
}
448456
RunMiddlewarePipeline(state_, MiddlewareHooks::SendMessageHooks(request));
449457
}
450458

0 commit comments

Comments
 (0)