ASP.NET Core HttpClientFactory on Google Cloud Run randomly times out outbound HTTP/2 requests only during autoscaling spikes

8 hours ago 1
ARTICLE AD BOX

I have an ASP.NET Core Web API running on Google Cloud Run that uses IHttpClientFactory to call another Cloud Run service over HTTP/2.

Everything works normally under steady traffic.

However, during sudden autoscaling spikes, outbound requests randomly fail with TaskCanceledException / HttpRequestException even though the downstream service remains healthy.

Reducing PooledConnectionLifetime lowers the failure rate, but increases CPU and TLS overhead significantly.

builder.Services.AddHttpClient("api") .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { EnableMultipleHttp2Connections = false, PooledConnectionLifetime = TimeSpan.FromMinutes(20), MaxConnectionsPerServer = 500 });

Is this caused by stale HTTP/2 pooled connections during Cloud Run autoscaling, or is there a recommended SocketsHttpHandler configuration for Cloud Run-to-Cloud Run communication?

Read Entire Article