fix: Fix race condition in GrpcDirectStreamController#1537
fix: Fix race condition in GrpcDirectStreamController#1537igorbernstein2 merged 2 commits intogoogleapis:mainfrom
Conversation
|
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
|
|
||
| clientCall.start(new ResponseObserverAdapter(), new Metadata()); | ||
|
|
||
| this.hasStarted = true; |
There was a problem hiding this comment.
Why this line is moved from before clientCall.start to after it? I don't know the exact use case of startCommon, but it could be an issue if clientCall.start is taking some time to complete and startCommon is being called another time.
There was a problem hiding this comment.
hasStarted is meant to be a barrier before we could interact with a stream, grpc has the invariant that you can't call request before a stream is started. Before the barrier is opened, we simply increment the request count. The original assumption is that the only thing that could call request() this is in onStart() and onResponse(). However this is not the case when retry is enabled where controller could be created from a different thread.
I don't think clientCall.start() taking a long time will be a problem here. GrpcDirectStreamController#start() is only called from here and here for bidi, which means that every callable.call() will create a new controller instance, so I don't think there's a race condition here.








Fix the race condition in
GrpcDirectStreamControllerwhen controller.request() is called when there's a retry attempt. This could causeIllegalStateException:This get triggered when
GrpcDirectStreamControlleris created from a retry thread and controller.request() get called from another thread: