-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix race condition in GrpcDirectStreamController #1537
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it makes sense.
Fix the race condition in
GrpcDirectStreamController
when controller.request() is called when there's a retry attempt. This could causeIllegalStateException
:This get triggered when
GrpcDirectStreamController
is created from a retry thread and controller.request() get called from another thread: