-
Notifications
You must be signed in to change notification settings - Fork 367
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
Using built-in DI registration functions like AddPublisherServiceApiClient
can potentially cause thread starvation during high load at startup.
#11092
Comments
Thanks for the detailed report. I'll assign this to Amanda who looked into this previously... I suspect there are no "easy" fixes for this, but we'll see. The aspect I think I'd focus on is why threads are blocking rather than using async operations. If we're doing something there that could become async (or offer a new async overload) that might be helpful. But if it's the DI system itself which is blocking threads, that could be tricky. |
OK, I might I have a fix for this. It's exactly the same issue as before, sorry we dindn't realize earlier and re-introduced it ourselves. |
We need to discuss some things internally, but you can implement this workaround while we do so. The workaround is basically to fetch the application default credential yourself so it has already been obtained by the time the clients are built. Note that you don't have to do anything with it, as the application default credential is cached the first time is fetched. Your DI code would look like this: // Workaround for https://github.com/googleapis/google-cloud-dotnet/issues/11092
GoogleCredential.GetApplicationDefaultCredential();
builder.Services.AddPublisherServiceApiClient(); I'll get back on this thread when we know more. |
We are going to document the workaround (#11142) while we evaluate our options. So I'll downgrade this issue to a P3 not because we are not looking into it, but because there's a straightforward documented workaround. I'll come back when I know more. |
Using the built-in DI registration functions like
AddPublisherServiceApiClient
can potentially cause thread starvation during high load at startup.Environment details
Google.Cloud.PubSub.V1->3.2.0
Steps to reproduce
Unfortunately there is no way to reliably reproduce it, we've encountered this issue only twice in the past two months
Create a basic ASP.NET Core with the DI registration code in
Program.cs
:builder.Services.AddPublisherServiceApiClient();
Add a basic controller that accepts an
PublisherServiceApiClient
in the constructor and publishes Pub/Sub messages usingawait PublisherServiceApiClient.PublishAsync
Send a ton of traffic over a longer period of time.
When a new instance starts (e.g due to scaling), under rare circumstances this can cause the exact same issue as described here googleapis/google-api-dotnet-client#1807, where the fetching of the Application Default Credentials might cause thread starvation.
To summarize this previous issue:
As you can see in that issue, we've been hit by this exact issue 3 years ago, but in a different service of ours, under different circumstances using some manual initialization logic.
The reason I'm reporting this again is that this is now happening to us using the build-in DI functions like
AddPublisherServiceApiClient
, which one would assume to the right thing™ already and don't run into this issue.Not sure what the best way to solve this is, as the async nature of the credentials fetching makes this inherently harder with DI. Maybe the library should have an internal synchronization mechanism when fetching the Application Default Credentials? Or should the documentation mention that we should do this manually beforehand?
The text was updated successfully, but these errors were encountered: