Skip to content
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

[Bug] IDispatcher cannot be resolved when connection to Kafka fails #2376

Open
Thijmen opened this issue Nov 23, 2022 · 2 comments
Open

[Bug] IDispatcher cannot be resolved when connection to Kafka fails #2376

Thijmen opened this issue Nov 23, 2022 · 2 comments

Comments

@Thijmen
Copy link
Contributor

Thijmen commented Nov 23, 2022

Describe the bug

Sample project: https://github.com/Thijmen/Brighter/tree/idispatcher-exception-poc/samples/KafkaTaskQueue/KafkaOutbox

When using

services.AddHostedService<ServiceActivatorHostedService>();

And later connecting to Kafka (with an invalid hostname, for example), the Exception to the user is not very clear.

Unhandled exception: System.InvalidOperationException: Unable to resolve service for type 'Paramore.Brighter.ServiceActivator.IDispatcher' while attempting to activate 'Paramore.Brighter.ServiceActivator.Extensions.Hosting.ServiceActivatorHostedService'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateEnumerable(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at KafkaOutbox.Program.Main(String[] args) in /Users/thijmen.stavenuiter/Code/brighter-fork/samples/KafkaTaskQueue/KafkaOutbox/Program.cs:line 12

If you dont use the hosted service, you'll get a better exception:

 Paramore.Brighter.ChannelFailureException: Error finding topic com.kafka.mapping
       ---> Confluent.Kafka.KafkaException: Local: Broker transport failure
         at Confluent.Kafka.Impl.SafeKafkaHandle.GetMetadata(Boolean allTopics, SafeTopicHandle topic, Int32 millisecondsTimeout)
         at Confluent.Kafka.AdminClient.GetMetadata(String topic, TimeSpan timeout)

To Reproduce

Open Sample project: https://github.com/Thijmen/Brighter/tree/idispatcher-exception-poc/samples/KafkaTaskQueue/KafkaOutbox
And run it :)

Exceptions (if any)

Unhandled exception: System.InvalidOperationException: Unable to resolve service for type 'Paramore.Brighter.ServiceActivator.IDispatcher' while attempting to activate 'Paramore.Brighter.ServiceActivator.Extensions.Hosting.ServiceActivatorHostedService'.
@Thijmen
Copy link
Contributor Author

Thijmen commented Nov 24, 2022

I'm all for opening a PR, however I think this requires internal discussion on how to achieve this. Should Brighter even inject the dispatcher eventhough it's possibly not available?

@iancooper iancooper self-assigned this Nov 25, 2022
@iancooper iancooper assigned holytshirt and unassigned iancooper Nov 30, 2022
@iancooper iancooper changed the title IDispatcher cannot be resolved when connection to Kafka fails [Bug] IDispatcher cannot be resolved when connection to Kafka fails Jan 5, 2023
@iancooper
Copy link
Member

There is some useful thinking here about environment checks, particularly as cli check: https://jeremydmiller.com/2019/10/01/environment-checks-and-better-command-line-abilities-for-your-net-core-application/ and it came from this Twitter thread which has some interesting observations: https://twitter.com/RogerAlsing/status/1636273862718398464?s=20 which could relate to this problem - how do we do better diagnostics. So for example we could register "env" checks from our transports and inbox/outboxes then search for and run them all, if you request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants