jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 62 forks source link

If WSS connection fails the plugin cannot try other transports (SSE and LP) #38

Closed misici234 closed 8 months ago

misici234 commented 3 years ago

When I run the following test code main.txt I get this error flutter: SigChar url is https://confidential_link/... flutter: Starting HubConnection. flutter: Starting connection with transfer format 'TransferFormat.text'. flutter: Sending negotiation request: https://confidential_link/... flutter: Selecting transport 'HttpTransportType.webSockets'. flutter: (WebSockets transport) Connecting. flutter: WebSocket connected to wss://confidential_link/... flutter: The HttpConnection connected successfully. flutter: Sending handshake request. flutter: (WebSockets transport) sending data. String data of length '32'. flutter: Using HubProtocol 'json'. flutter: (WebSockets transport) socket closed. flutter: HttpConnection.stopConnection(null) called while in state ConnectionState.disconnecting. flutter: Connection disconnected with error 'Exception: Server timeout elapsed without receiving a message from the server.'. flutter: HubConnection.connectionClosed(Exception: Server timeout elapsed without receiving a message from the server.) called while in state HubConnectionState.disconnected. flutter: Hub handshake failed with error 'Exception: Server timeout elapsed without receiving a message from the server.' during start(). Stopping HubConnection. flutter: Call to HttpConnection.stop(Exception: Server timeout elapsed without receiving a message from the server.) ignored because the connection is already in the disconnected state. flutter: HubConnection failed to start successfully because of error '{Exception: Server timeout elapsed without receiving a message from the server..toString}'. [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: Exception: Server timeout elapsed without receiving a message from the server.

Our ASP.NET Core application doesn't support WebSockets but it supports Server Sent Events for some reason which I don't know. Your plugin has a problem to switch from WSS to SSE if it fails to communicate using WSS. When I explicitly specify SSE logging: (level, message) => print(message), transport: HttpTransportType.serverSentEvents); then it works fine. The signalr_client 0.1.6 doesn't have this problem and that's the reason I still use it but I want to replace it with your plugin as soon as you resolve this problem. Please go there and see how they made this work. If you need our URL to test then let me know but you need to disable WSS transport on your server and you'll be fine to reproduce this issue.

misici234 commented 3 years ago

here is correct line final httpOptions = new HttpConnectionOptions(logging: (level, message) => print(message), transport: HttpTransportType.serverSentEvents);

misici234 commented 3 years ago

I was looking the code and the problem is in web_socket_transport.dart file. Function @override Future<void> connect(String url, TransferFormat transferFormat) async {} should throw an Exception if it cannot connect and should not have its own try/catch block so that outside try/catch block can catch the Exception and move to next transport. Hope this helps.

misici234 commented 3 years ago

Hi Jamie, are you going to fix this problem? As far as I can see this is not trivial fix and I don't feel comfortable to do it myself.