Xabaril / AspNetCore.Diagnostics.HealthChecks

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

SignalR healthcheck issue #524

Closed ChrisProlls closed 4 years ago

ChrisProlls commented 4 years ago

Please, fill the following sections to help us fix the issue

What happened: I tried to use the SignalR healthcheck but I faced with a Object reference not set to an instance of an object. into the health check portal. image

What you expected to happen: I expect the health check to work properly

Source code sample: I used this code :

services.AddHealthChecks()
                .AddSignalRHub("/Hub", name: "signalr hub")
                .AddSignalRHub("/UploaderHub", name: "signalr uploader")
                .AddHealthChecksUI(setup =>
                {
                    setup.AddHealthCheckEndpoint("HealthCheck", "/healthz");
                    setup.SetEvaluationTimeInSeconds(60);
                })
                .AddInMemoryStorage();

and for my route configuration

app
                .UseHealthChecks("/healthz", new HealthCheckOptions
                {
                    Predicate = _ => true,
                    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
                })
                .UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<UploaderHub>("/UploaderHub");
                endpoints.MapHub<ClientHub>("/Hub");
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
                endpoints.MapHealthChecksUI(options => options.UIPath = "/health-ui");
            });

Into the health check, I assume that this line returns null, but can't figure out why:

new HubConnectionBuilder()
                    .WithUrl(url)
                    .Build();

Anything else we need to know?: Ths UI portal is showing correctly, others health check (sql, redis) are working properly.

Environment:

unaizorrilla commented 4 years ago

Hi @ChrisProlls

Thanks for submitting the issue!

Well, the issue is related with your Uri configuration for the SignalR hubs. AddSignalRHub need the hub uri, not the path string, ie /hub.

When the healthcheck perform the iteration, the HubConnectionBuilder throw because this uri is not valid.

Can you set the valid Uri for the Hub and test if this works well?

Please, close the issue if this solve the problem!

ChrisProlls commented 4 years ago

So, if I understand correctly, I need the full SignalR hub URL into my Startup ? For example : https://mydomain.com/hub ?

Into the startup it's not possible to retrive the domain name, so I would have to store it into the configuration files.

unaizorrilla commented 4 years ago

@ChrisProlls

Yeap, you need to set the uri in configuration vars! Is not easy to get the domain name at startup time