Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
3.98k stars 770 forks source link

Azure.IoTHub Creates a new ServiceClient causing socket exhaustion #2211

Open pregress opened 1 month ago

pregress commented 1 month ago

What happened:

IoTHubHealthCheckCreates a new ServiceClient, this is a problem, see: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.serviceclient?view=azure-dotnet#remarks

Also currently there is no way to use managed identity to connect to iothub, only connection strings are possible. Would be better if this works the same as eg: Azure.Data.Tables where you can inject the clients using already registered services.

Same goes for the RegistryManager https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.registrymanager?view=azure-dotnet#remarks

What you expected to happen: Keep the Azure apis consistent eg: .AddIotHub(sp => sp.GetService<ServiceClient>(), sp => sp.GetService<RegistryManager>(), options => ...

Maybe split it per check, or handle clients being null if they aren't needed depending on the options.

How to reproduce it (as minimally and precisely as possible): register the current AddIotHub and monitor for socket exhaustion.

Source code sample: https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/src/HealthChecks.Azure.IoTHub/IoTHubHealthCheck.cs#L43 #

Anything else we need to know?:

Environment: