Skip to content

Signalr server sent events not firing onclose/reconnect event on expiration of JWT #23503

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

Closed
Jonno12345 opened this issue Jun 30, 2020 · 1 comment
Labels
area-signalr Includes: SignalR clients and servers

Comments

@Jonno12345
Copy link

I raised this issue over at the Azure SignalR github (Azure/azure-signalr#943) however I suspect this is an issue with the Javascript client itself. It does however render us unable to use the ServerSentEvents transport on Azure SignalR currently.

Describe the bug

To test that our reconnection logic on the expiration of our Azure SignalR JWT worked correctly, I set the AccessTokenLifetime to 1 minute.

services.AddSignalR()
                .AddNewtonsoftJsonProtocol()
                .AddAzureSignalR(o =>
                {
                    o.AccessTokenLifetime = TimeSpan.FromMinutes(1);
                });
        

Whilst using WebSockets, as expected, there was no disconnection after 1 minute and the connection remained open for the duration of testing.
Whilst using LongPolling, as soon as a 401 error is received from a long poll response, the onclose event is fired allowing us to manage a reconnection.

However, whilst using SSE, the occasional ping or attempt to post a message back to the Azure SignalR server results in a 401 error that does not appear to initiate an onclose or reconnect event. As such, we have no way to know that the communication between the server has now broken, and cannot force it to renegotiate.

This makes SSE functionally unusable with Azure SignalR as our clients will permanently disconnect after the 1 hour JWT timeout.

To Reproduce

As above, using a short JWT expiry and the following javascript connection:

new signalR.HubConnectionBuilder()
            .withUrl(connectionUrl,
                {
                    transport: signalR.HttpTransportType.ServerSentEvents,
                })
            .withAutomaticReconnect() //optional, but neither reconnection nor onclose are occurring
            .build();

Exceptions (if any)

The console fills with the following errors, however no attempt to reconnect trigger an 'onclose' or 'onreconnecting' event occurs.

image

With LongPolling, we receive a single error, followed by a reconnection (onclose without the withAutomaticReconnect())

Further technical details

  • Your Azure SignalR SDK version: Microsoft.Azure.SignalR@1.5.0
  • Your SignalR Client SDK version: Javascript - microsoft-signalr@3.1.3
@Jonno12345 Jonno12345 changed the title Server sent events not firing onclose/reconnect event on expiration of JWT Signalr server sent events not firing onclose/reconnect event on expiration of JWT Jun 30, 2020
@javiercn javiercn added the area-signalr Includes: SignalR clients and servers label Jun 30, 2020
@BrennanConroy
Copy link
Member

Dupe of #5283

Take a look at for possible workarounds #5283 (comment)

@ghost ghost locked as resolved and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

3 participants