googleapis / google-cloud-dotnet

Google Cloud Client Libraries for .NET
https://cloud.google.com/dotnet/docs/reference/
Apache License 2.0
931 stars 365 forks source link

SubscriberClientImpl.DisposeAsync throws exception #13647

Open anabnich opened 13 hours ago

anabnich commented 13 hours ago

Environment details

Steps to reproduce

  1. Create DI container
  2. Register a pubsub subscription
  3. Throw an exception in a class which is instantiated via DI injection.

result:

Unhandled exception. System.InvalidOperationException: Can only stop a started instance. at Google.Api.Gax.GaxPreconditions.CheckState(Boolean condition, String message) at Google.Cloud.PubSub.V1.SubscriberClientImpl.StopAsync(CancellationToken hardStopToken) at Google.Cloud.PubSub.V1.SubscriberClient.StopAsync(TimeSpan timeout) at Google.Cloud.PubSub.V1.SubscriberClientImpl.DisposeAsync() at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.DisposeAsync() --- End of stack trace from previous location --- at Microsoft.Extensions.Hosting.Internal.Host.g__DisposeAsync|21_0(Object o) at Microsoft.Extensions.Hosting.Internal.Host.DisposeAsync() at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) at WebApplication.Program.Main(String[] args)

Expected result: DisposeAsync does not throw an exception if it hasn't been started yet. The constructor exception will be caught in DI container and logged.

jskeet commented 10 hours ago

Thanks for reporting this. We'll look into it.