Skip to content

SignalR client doesn't reconnect after server failure #27762

@Spongman

Description

@Spongman

i have a simple SignalR hub, with the client code copied from https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-5.0#connect-to-a-hub

const connection = new signalR.HubConnectionBuilder()
    .withUrl("/chathub")
    .configureLogging(signalR.LogLevel.Information)
    .build();

async function start() {
    try {
        await connection.start();
        console.log("SignalR Connected.");
    } catch (err) {
        console.log(err);
        setTimeout(start, 5000);
    }
};

connection.onclose(start);

// Start the connection.
start();

and it works great, until the server shuts down & restarts.

when this happens:

  • the onclose callback is called
  • the connection.start() method is called
  • this initiates an XHR request to the server 'negotiate' URL. but, and here's the bug: it doesn't specify a timeout. this XHR request NEVER completes (because the server is down).
  • now i start the server back up.
  • but my script is screwed already. the start() call will never resolve it's promise, and the connection will never be resumed.

i could set a timeout and then start another start() call, but then i'd just be leaking XHR requests and promises all over the place.

the signalr library shouldn't be making XHR requests without specifying a timeout (NO library should ever make XHR requests without a timeout), and there should be a way for me to specify the timeout to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and serversbugThis issue describes a behavior which is not expected - a bug.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions