aspnet / AzureSignalR-samples

Code samples for Azure SignalR
MIT License
324 stars 388 forks source link

AzureSignalR connection correct, but not notifying #126

Open DavidStania opened 4 years ago

DavidStania commented 4 years ago

Hey Guys,

I have a smal problem after publishing my web app on azure and consuming AzureSignalR. After starting app, connection is working well and I can join groups. But if I push a Notification from my app like

 await hubContext.Clients.Groups(arbeitssystem.ShortId).SendAsync("StateChanged", arbeitssystem.ShortId);

groups were not notifyed.

setup.cs ConfigureServices

            services.AddSignalR().AddHubOptions<Hubs.TwinHub>(options =>
            {
                options.EnableDetailedErrors = true;
            }).AddAzureSignalR();
app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
                endpoints.MapHub<Hubs.TwinHub>("/TwinHubDashboard");
                endpoints.MapControllerRoute("api", "api/{controller}/{action}");
            });

But without .AddAzureSignalR(), so as local service, everything is working. Also after publishing on azure. Any ideas whats going wrong?

vwxyzh commented 4 years ago

@DavidStania It should be OK, can you repro the issue after restarting the service instance? And can you send your resource id to my email address: zhyan@microsoft.com?

DavidStania commented 4 years ago

@vwxyzh after restarting service, problem still exists. ResourceId I sended to you. Thank you.

vwxyzh commented 4 years ago

Let me check the service log.

DavidStania commented 4 years ago

I don't know why, but i got this erro

Microsoft.Azure.SignalR.ServiceConnection[2]
      Failed to connect to '(Primary)https://xxxx.service.signalr.net', will retry after the back off period. Error detail: The server returned status code '400' when status code '101' was expected.. The server returned status code '400' when status code '101' was expected.. Id: 38eb1154-da23-4313-8156-8e913d212cb1

Today it is not possible to established connection.

Yesterday, same doing: image

DavidStania commented 4 years ago

found my mistake!

Right

 var connection = new signalR.HubConnectionBuilder()
        .withUrl('/TwinHubDashboard')
        .configureLogging(signalR.LogLevel.Information)
        .build();

Wrong

    var connection = new signalR.HubConnectionBuilder()
        .withUrl('/TwinHubDashboard', {
            skipNegotiation: true,
            transport: signalR.HttpTransportType.WebSockets
        })
        .configureLogging(signalR.LogLevel.Information)
        .build();

while skipping Negotation, connection never starts with azure service. After removing this part, everything is working like expected.

@vwxyzh Thank you for support.

dazinator commented 4 years ago

i am seeing the same error, but I am not skipping negotiation. The client tries to send a negotiate request and get's an error 500 response

Request URL: https://foo-dev-pr167.azurewebsites.net/hubs/webnotifications/negotiate?negotiateVersion=1 Request Method: POST Status Code: 500 Remote Address: 137.117.203.130:443 Referrer Policy: no-referrer-when-downgrade

Looking at the logs on the server:

I am seeing this repeated:

Client negotiate failed: Azure SignalR Service is not connected yet, please try again later. 29 Jun 2020 18:13:27.805 Failed to connect to '(Primary)https://foo-dev.service.signalr.net', will retry after the back off period. Error detail: The server returned status code '400' when status code '101' was expected.. The server returned status code '400' when status code '101' was expected.. Id: 13f27c22-9f02-47c0-8c78-d83c157b4ce7 29 Jun 2020 18:13:27.804 Transport is stopping. 29 Jun 2020 18:13:27.716 Starting transport. Transfer mode: Binary. Url: 'wss://foo-dev.service.signalr.net/server/?hub=43e1b6f6e3f14c31b4ddbccf011c9b0d_webnotificationhub&cid=13f27c22-9f02-47c0-8c78-d83c157b4ce7'.

I logged this issue: https://github.com/Azure/azure-signalr/issues/944 already but perhaps this is related?