Azure / azure-signalr

Azure SignalR Service SDK for .NET
https://aka.ms/signalr-service
MIT License
427 stars 101 forks source link

After migration to .net8 SignalR stopped to work #1933

Closed w-johnny closed 6 months ago

w-johnny commented 6 months ago

Describe the bug

Recently we migrated our solution from .net6 to .net8. After that SignalR stopped to work. There were not code changes - only migration of the .net version + upgrade of all nuget packages.

To Reproduce

This is the SignalR configuration:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        //...
        services.AddChatEngineDependencies(_configuration);
        //...
    }

    public void Configure(IApplicationBuilder app, IHostEnvironment env)
    {
        //...
        app.UseChatEngine();
        //...
    }
}

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddChatEngineDependencies(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddControllers();
        services.AddSignalR()
            .AddAzureSignalR(configuration.GetConnectionString("AzureSignalR"));
        //...
    }
}

public static class ApplicationBuilderExtensions
{
    public static IApplicationBuilder UseChatEngine(this IApplicationBuilder app)
    {
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHub<ChatHub>("/hub").RequireAuthorization();
        });
        return app;
    }
}

Exceptions (if any)

vendor-957f9e95.js:508 [2024-05-06T10:25:40.633Z] Error: Server returned handshake error: SignalR Service is now in 'Default' service mode. Current mode works as a proxy that routes client traffic to the connected app servers. However app servers are not connected.
log @ vendor-957f9e95.js:508
_processHandshakeResponse @ vendor-957f9e95.js:508
_processIncomingData @ vendor-957f9e95.js:508
HubConnection.connection.onreceive @ vendor-957f9e95.js:508
it.onmessage @ vendor-957f9e95.js:508
vendor-957f9e95.js:508 [2024-05-06T10:25:40.634Z] Error: Connection disconnected with error 'Error: Server returned handshake error: SignalR Service is now in 'Default' service mode. Current mode works as a proxy that routes client traffic to the connected app servers. However app servers are not connected.'.
log @ vendor-957f9e95.js:508
_stopConnection @ vendor-957f9e95.js:508
transport.onclose @ vendor-957f9e95.js:508
_close @ vendor-957f9e95.js:508
it.onmessage @ vendor-957f9e95.js:508
vendor-957f9e95.js:508 Uncaught (in promise) Error: Server returned handshake error: SignalR Service is now in 'Default' service mode. Current mode works as a proxy that routes client traffic to the connected app servers. However app servers are not connected.
    at HubConnection._processHandshakeResponse (vendor-957f9e95.js:508:35675)
    at HubConnection._processIncomingData (vendor-957f9e95.js:508:34368)
    at HubConnection.connection.onreceive (vendor-957f9e95.js:508:28393)

Further technical details

w-johnny commented 6 months ago

Ok, I've found an issue myself. The problem was the fact that in Configure method UseEndpoints was called twice - from within Configure and from UseChatEngine. Once I moved the logic to single UseEndpoints it started to work again.