Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Transport Fallback #1373

Closed
mikaelm12 opened this issue Jan 30, 2018 · 7 comments
Closed

Transport Fallback #1373

mikaelm12 opened this issue Jan 30, 2018 · 7 comments

Comments

@mikaelm12
Copy link
Contributor

Looks like it will be coming back.

@mikaelm12 mikaelm12 added this to the 2.1.0-preview2 milestone Jan 30, 2018
@muratg muratg mentioned this issue Jan 30, 2018
55 tasks
@mikaelm12 mikaelm12 self-assigned this Jan 31, 2018
@JinsPeter
Copy link

Does this means, There will a Transport type automatic which will take care of the connection change. I mean if Websocket work, Will it switch itself to Long Polling.??

@mikaelm12
Copy link
Contributor Author

The idea now is that if you fail to initially connect with the requested transport, we will try to fall back to other transports in the order WebSockets, Server Sent Events, then LongPolling. The design isn't completely finalized but we have decided that we want to add the core fallback functionality back

@JinsPeter
Copy link

JinsPeter commented Jan 31, 2018

This is out of curiosity.. I have not yet contributed to any open source project and may have limited knowledge in that matter.
This fallback feature is handled in the signalR client package ryt?
I have done a fallback in my angular 5 TS application which looks like

manageSignalRHubConnection() {
        this._transportType = TransportType.WebSockets;
        this._hubConnection = new HubConnection(signalrHubUrl, { transport: this._transportType });
        this.startHubConnection();
    }

 startHubConnection() {
        this._hubConnection.start()
            .then(() => {
                this._hubConnection.invoke('JoinGroup', ClientAppType.Dashboard)
                    .then(() => {
                        this.refreshFeed();
                    });
            })
            .catch(err => {
                console.error(`Error while establishing ${TransportType[this._transportType]} connection`, err);
                //fallback
                switch (this._transportType) {
                    case TransportType.WebSockets: this._transportType = TransportType.ServerSentEvents;
                        break;
                    case TransportType.ServerSentEvents: this._transportType = TransportType.LongPolling;
                        break;
                    default: this._transportType = TransportType.LongPolling;
                        break;
                }
                this._hubConnection = new HubConnection(signalrHubUrl, { transport: this._transportType });
                this.startHubConnection();
            });
        this._hubConnection.on('ShowStatus', (activeDevices: DeviceStatus[]) => {
            this.zone.run(() => {
                this.activeDevices = activeDevices;
            });
        });
        this._hubConnection.onclose(err => {
            console.error("Connection was closed.", err);
        });
    }

Is the fall back functionality more or less this, handled internally.??

@analogrelay
Copy link
Contributor

analogrelay commented Jan 31, 2018

Fallback will need to be implemented in both clients (C# and JS) and we'll need to do some design to figure out exactly how we want to accomplish it. There are lots of edge cases that need to be considered when building a general-purpose feature like this :). I'm not sure we'll do any fallback after the connection is established, for example, as that has caused a lot of problems in previous versions of SignalR because you have to deal with what happens with messages sent while transport fallback occurs.

If you're looking for something to contribute back to the project, I don't think this is a great fit, I'm afraid. We certainly appreciate your interest, but we haven't even really defined what this feature is going to look like yet :).

@alexzaytsev-newsroomly
Copy link

@anurse re: because you have to deal with what happens with messages sent while transport fallback occurs. Wouldn't you simply open the second connection, then set the first one to draining (e.g. let old messages finish but not accept new messages); for further requests with the same client id use the second connection, then disconnect at the re-negotiating end?

@analogrelay
Copy link
Contributor

analogrelay commented Feb 16, 2018

then set the first one to draining

Except that in the scenario we're talking about, the first transport failed at some arbitrary point with neither the server nor the client knowing for sure which messages made it through. To retransmit those messages the client and server need to manage sequence numbers, which is precisely what we're trying to avoid right now due to the complexities it created in SignalR 2.x

@mikaelm12
Copy link
Contributor Author

Initial commit is merged : adbd964
More work tracked here: #1554

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants