SignalR icon indicating copy to clipboard operation
SignalR copied to clipboard

JavaScript Client does not cause OnReconnected event to fire when using longPolling transport

Open darcon77 opened this issue 13 years ago • 2 comments

To reproduce

Client:

    var proxy = $.connection.chatHub;
    proxy.client.logMessage = function (message) {
        console.log(message);
    };

    $.connection.hub.logging = true;
    $.connection.hub.connectionSlow(function () {
        console.log('We are currently experiencing difficulties with the connection.')
    });
    $.connection.hub.error(function (error) {
        console.log('SignalR error: ' + error)
    });
    $.connection.hub.start({ transport: 'longPolling' }).done(function () {
        console.log("Started");
    });

Server:

public class ChatHub : Hub
{

    public override Task OnConnected()
    {
        Clients.Caller.logMessage("Connected");
        return base.OnConnected();
    }

    public override Task OnDisconnected()
    {
        Clients.Caller.logMessage("Disconnected");
        return base.OnDisconnected();
    }

    public override Task OnReconnected()
    {
        Clients.Caller.logMessage("Reconnected");
        return base.OnReconnected();
    }
}

If I don't specify transport, foreverFrame is used. Connection is successfully established and console shows "Connected" message. If I recycle app pool manually or cause the recycle by modifying web.config, console shows "Reconnected" message, indicating that OnReconnected method of the hub was fired. But if I specify longPolling as my transport, after the initial load console shows "Connected" message. However, when I cause app pool recycle, "Reconnected" message never shows up. Console just keeps logging SignalR: Attempting to connect to 'http://www.myhost.com/signalr/poll?transport=longPolling&connectionToken=FMPkYXaM6FKXM57jmPSCmQQv...&tid=0' using longPolling every 110 seconds.

How should I restore connection to the server? Does the client know when there's no hub listening on the server side so that I can restart connection by $.connection.hub.start()?

darcon77 avatar Jun 21 '13 16:06 darcon77

This is an issue we'll look at for a future release.

davidfowl avatar Jun 22 '13 05:06 davidfowl

Verified that JS client and .Net 4.5 /4.0 clients raise reconnect request when App domain restart or app pool recycle, and OnReconnected event on server raise.

Xiaohongt avatar Jul 27 '13 06:07 Xiaohongt