Skip to content
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

Try to connect to server and get exception on call start(); #14

Closed
KovalenkoILja opened this issue Jun 2, 2020 · 10 comments
Closed

Try to connect to server and get exception on call start(); #14

KovalenkoILja opened this issue Jun 2, 2020 · 10 comments

Comments

@KovalenkoILja
Copy link

KovalenkoILja commented Jun 2, 2020

I try to open connect to server and on start get exception:

** {Exception: WebSocket closed with status code: 1002 (null).**

What am I doing wrong?

My code:

final connection = HubConnectionBuilder().withUrl(URL+'/ws/geo',
          HttpConnectionOptions(
            client: IOClient(HttpClient()..badCertificateCallback = (x, y, z) => true),
            logging: (level, message) => print('$level: $message'),
            accessTokenFactory: getToken,
          )).withAutomaticReconnect().build();
await connection.start();

Logs:
LogLevel.debug: Starting HubConnection. LogLevel.debug: Starting connection with transfer format 'TransferFormat.text'. LogLevel.debug: Sending negotiation request: https://ultapps.com/ws/geo/negotiate. LogLevel.debug: Selecting transport 'HttpTransportType.webSockets'. LogLevel.trace: (WebSockets transport) Connecting. LogLevel.information: WebSocket connected to wss://ultapps.com/ws/geo?id=-q9VeFkVBznJZKVRHg-o2g&access_token=<token>. LogLevel.debug: The HttpConnection connected successfully. LogLevel.debug: Sending handshake request. LogLevel.trace: (WebSockets transport) sending data. String data of length '32'. LogLevel.information: Using HubProtocol 'json'. LogLevel.trace: (WebSockets transport) socket closed. LogLevel.debug: HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connected. LogLevel.error: Connection disconnected with error 'Exception: WebSocket closed with status code: 1002 (null).'. LogLevel.debug: HubConnection.connectionClosed(Exception: WebSocket closed with status code: 1002 (null).) called while in state HubConnectionState.disconnected. LogLevel.debug: HttpConnection.stopConnection(null) called while in state ConnectionState.disconnected. LogLevel.debug: Call to HttpConnection.stopConnection(null) was ignored because the connection is already in the disconnected state. LogLevel.debug: Hub handshake failed with error 'Exception: WebSocket closed with status code: 1002 (null).' during start(). Stopping HubConnection. LogLevel.debug: Call to HttpConnection.stop(Exception: WebSocket closed with status code: 1002 (null).) ignored because the connection is already in the disconnected state. LogLevel.debug: HubConnection failed to start successfully because of error '{Exception: WebSocket closed with status code: 1002 (null)..toString}'.

@jamiewest
Copy link
Owner

The access_token part in your logs looks off and might be the issue. Did you modify the output of the logs to replace the actual token with <token>?

@KovalenkoILja
Copy link
Author

The access_token part in your logs looks off and might be the issue. Did you modify the output of the logs to replace the actual token with <token>?

Yes, i remove actual token from logs for safety.

@Emelio
Copy link

Emelio commented Oct 10, 2020

I keep getting this error

HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connecting.

@zuboje
Copy link

zuboje commented Nov 9, 2020

I am having the very same error, except my, I don't use access tokens, my SignalR server is open to everyone. I use .NET Core 3.1 on Windows server (for some reason on Linux server I had issues).

final hubConnection = HubConnectionBuilder().withUrl(rtcUrl, HttpConnectionOptions(logging: (level, message) => print(message))).withAutomaticReconnect().build();

Now the server does not disconnect if I start the connection and keep it sitting there, it disconnects at some point after data exchange starts. I just randomly receive the error below. I have noticed something when I set transport under connection options to HttpTransportType.longPolling it runs, yet at some point, it still disconnects. I tried reconnecting but I am unable to do so. I figure out the approximate time to disconnect is about 2 minutes (default SignalR time to disconnect is 110 seconds). I have tried to setup

if (hubConnection.state == HubConnectionState.disconnected && hubConnection.state != HubConnectionState.connecting && hubConnection.state != HubConnectionState.disconnecting){...}

I still receive the exception that I cannot call start HubConnection failed to start successfully because of error '{type 'NoSuchMethodError' is not a subtype of type 'Exception'.toString}'. All details are in the log below.

My Server:

image

I/flutter ( 9610): WebSocket connected to wss://URL?id=jOxUVuMauABfLhE4VmoOYw.
I/flutter ( 9610): (WebSockets transport) socket closed.
I/flutter ( 9610): HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connecting.
I/flutter ( 9610): Call to HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) was ignored because the connection is still in the connecting state.
E/flutter ( 9610): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Exception: HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) was called while the connection is still in the connecting state.
�[38;5;248mE/flutter ( 9610): #0 HttpConnection._stopConnection�[39;49m
package:signalr_core/src/http_connection.dart
�[38;5;248mE/flutter ( 9610): #1 HttpConnection._startTransport.�[39;49m
package:signalr_core/src/http_connection.dart
�[38;5;248mE/flutter ( 9610): #2 WebSocketTransport._close�[39;49m
package:signalr_core/…/transports/web_socket_transport.dart
�[38;5;248mE/flutter ( 9610): #3 WebSocketTransport.connect.�[39;49m
package:signalr_core/…/transports/web_socket_transport.dart
�[38;5;244mE/flutter ( 9610): #4 _rootRun (dart:async/zone.dart:1182:47)�[39;49m
�[38;5;244mE/flutter ( 9610): #5 _CustomZone.run (dart:async/zone.dart:1093:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #6 _CustomZone.runGuarded (dart:async/zone.dart:997:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #7 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:410:13)�[39;49m
�[38;5;244mE/flutter ( 9610): #8 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:420:15)�[39;49m
�[38;5;244mE/flutter ( 9610): #9 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:305:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #10 _ForwardingStream._handleDone (dart:async/stream_pipe.dart:101:10)�[39;49m
�[38;5;244mE/flutter ( 9610): #11 _ForwardingStreamSubscription._handleDone (dart:async/stream_pipe.dart:165:13)�[39;49m
�[38;5;244mE/flutter ( 9610): #12 _rootRun (dart:async/zone.dart:1182:47)�[39;49m
�[38;5;244mE/flutter ( 9610): #13 _CustomZone.run (dart:async/zone.dart:1093:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #14 _CustomZone.runGuarded (dart:async/zone.dart:997:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #15 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:410:13)�[39;49m
�[38;5;244mE/flutter ( 9610): #16 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:420:15)�[39;49m
�[38;5;244mE/flutter ( 9610): #17 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:305:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #18 _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:816:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #19 _StreamController._closeUnchecked (dart:async/stream_controller.dart:671:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #20 _StreamController.close (dart:async/stream_controller.dart:664:5)�[39;49m
�[38;5;244mE/flutter ( 9610): #21 new _WebSocketImpl._fromSocket. (dart:_http/websocket_impl.dart:1157:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #22 _rootRunBinary (dart:async/zone.dart:1214:47)�[39;49m
�[38;5;244mE/flutter ( 9610): #23 _CustomZone.runBinary (dart:async/zone.dart:1107:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #24 _CustomZone.runBinaryGuarded (dart:async/zone.dart:1013:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #25 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:376:15)�[39;49m
�[38;5;244mE/flutter ( 9610): #26 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:391:18)�[39;49m
�[38;5;244mE/flutter ( 9610): #27 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:294:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #28 _SinkTransformerStreamSubscription._addError (dart:async/stream_transformers.dart:83:11)�[39;49m
�[38;5;244mE/flutter ( 9610): #29 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:123:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #30 _HttpDetachedStreamSubscription._maybeScheduleData. (dart:_http/http_parser.dart:178:20)�[39;49m
�[38;5;244mE/flutter ( 9610): #31 _rootRun (dart:async/zone.dart:1182:47)�[39;49m
�[38;5;244mE/flutter ( 9610): #32 _CustomZone.run (dart:async/zone.dart:1093:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #33 _CustomZone.runGuarded (dart:async/zone.dart:997:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #34 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)�[39;49m
�[38;5;244mE/flutter ( 9610): #35 _rootRun (dart:async/zone.dart:1190:13)�[39;49m
�[38;5;244mE/flutter ( 9610): #36 _CustomZone.run (dart:async/zone.dart:1093:19)�[39;49m
�[38;5;244mE/flutter ( 9610): #37 _CustomZone.runGuarded (dart:async/zone.dart:997:7)�[39;49m
�[38;5;244mE/flutter ( 9610): #38 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)�[39;49m
�[38;5;244mE/flutter ( 9610): #39 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)�[39;49m
�[38;5;244mE/flutter ( 9610): #40 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)�[39;49m
E/flutter ( 9610):
I/flutter ( 9610): The HttpConnection connected successfully.
I/flutter ( 9610): Sending handshake request.
I/flutter ( 9610): Hub handshake failed with error 'NoSuchMethodError: The method 'send' was called on null.
I/flutter ( 9610): Receiver: null
I/flutter ( 9610): Tried calling: send("{"protocol":"json","version":1}\u001e")' during start(). Stopping HubConnection.
I/flutter ( 9610): HubConnection failed to start successfully because of error '{type 'NoSuchMethodError' is not a subtype of type 'Exception'.toString}'.

E/flutter ( 9610): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Read failed
E/flutter ( 9610):
I/flutter ( 9610): The HttpConnection connected successfully.
I/flutter ( 9610): Sending handshake request.
I/flutter ( 9610): (WebSockets transport) sending data. String data of length '32'.
I/flutter ( 9610): Hub handshake failed with error 'NoSuchMethodError: The getter 'sink' was called on null.
I/flutter ( 9610): Receiver: null
I/flutter ( 9610): Tried calling: sink' during start(). Stopping HubConnection.
I/flutter ( 9610): HubConnection failed to start successfully because of error '{type 'NoSuchMethodError' is not a subtype of type 'Exception'.toString}'.

@zuboje
Copy link

zuboje commented Nov 11, 2020

@jamiewest any ideas?

@jamiewest
Copy link
Owner

I think toString is getting called on an exception that hadn't been cast as an exception. I'm off today so I will see if i can track down the problems mentioned in the issue. Thanks all for everyone's patience on this.

@jamiewest
Copy link
Owner

@zuboje I committed a few bits earlier, could try them out and let me know the outcome?

Update your reference in pubspec.yaml to the following:

  signalr_core:
    git: 
      url: https://github.com/jamiewest/signalr_core.git
      ref: 3e8abe6e5ac1dd9dd2f18c0df91bfd9c8ba8a4af

@zuboje
Copy link

zuboje commented Nov 13, 2020

@jamiewest it looks like the problem is resolved. I am no longer receiving an error.

@joeyyy688
Copy link

Hello, I keep getting a similar error to this any help?
These are the error logs...
I/flutter (14832): Starting HubConnection.
I/flutter (14832): Starting connection with transfer format 'TransferFormat.text'.
I/flutter (14832): (WebSockets transport) Connecting.
I/flutter (14832): WebSocket connected to ws:// removed for privacy reasons
I/flutter (14832): The HttpConnection connected successfully.
I/flutter (14832): Sending handshake request.
I/flutter (14832): (WebSockets transport) socket closed.
I/flutter (14832): HttpConnection.stopConnection(Exception: WebSocket closed with status code: 1002 (null).) called while in state ConnectionState.connected.
I/flutter (14832): Connection disconnected with error 'Exception: WebSocket closed with status code: 1002 (null).'.
E/flutter (14832): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Bad state: Future already completed
E/flutter (14832): #0 _AsyncCompleter.complete (dart:async/future_impl.dart:45:31)
E/flutter (14832): #1 TransportSendQueue.stop
package:signalr_core/src/http_connection.dart:655
E/flutter (14832): #2 HttpConnection._stopConnection
package:signalr_core/src/http_connection.dart:291
E/flutter (14832): #3 HttpConnection._startTransport.
package:signalr_core/src/http_connection.dart:457
E/flutter (14832): #4 WebSocketTransport._close
package:signalr_core/…/transports/web_socket_transport.dart:130
E/flutter (14832): #5 WebSocketTransport.connect.
package:signalr_core/…/transports/web_socket_transport.dart:85
E/flutter (14832): #6 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (14832): #7 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (14832): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (14832): #9 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:394:13)
E/flutter (14832): #10 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:404:15)
E/flutter (14832): #11 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:291:7)
E/flutter (14832): #12 _ForwardingStream._handleDone (dart:async/stream_pipe.dart:99:10)
E/flutter (14832): #13 _ForwardingStreamSubscription._handleDone (dart:async/stream_pipe.dart:161:13)
E/flutter (14832): #14 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (14832): #15 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (14832): #16 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (14832): #17 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:394:13)
E/flutter (14832): #18 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:404:15)
E/flutter (14832): #19 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:291:7)
E/flutter (14832): #20 _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:741:19)
E/flutter (14832): #21 _StreamController._closeUnchecked (dart:async/stream_controller.dart:596:7)
E/flutter (14832): #22 _StreamController.close (dart:async/stream_controller.dart:589:5)
E/flutter (14832): #23 new _WebSocketImpl._fromSocket. (dart:_http/websocket_impl.dart:1157:19)
E/flutter (14832): #24 _rootRunBinary (dart:async/zone.dart:1378:47)
E/flutter (14832): #25 _CustomZone.runBinary (dart:async/zone.dart:1272:19)
E/flutter (14832): #26 _CustomZone.runBinaryGuarded (dart:async/zone.dart:1178:7)
E/flutter (14832): #27 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:360:15)
E/flutter (14832): #28 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:375:18)
E/flutter (14832): #29 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:280:7)
E/flutter (14832): #30 _SinkTransformerStreamSubscription._addError (dart:async/stream_transformers.dart:75:11)
E/flutter (14832): #31 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:113:7)
E/flutter (14832): #32 _HttpDetachedStreamSubscription._maybeScheduleData. (dart:_http/http_parser.dart:178:20)
E/flutter (14832): #33 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (14832): #33 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (14832): #34 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (14832): #35 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (14832): #36 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)
E/flutter (14832): #37 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (14832): #38 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (14832): #39 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (14832): #40 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)
E/flutter (14832): #41 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (14832): #42 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (14832):
I/flutter (14832): Hub handshake failed with error 'Exception: Connection stopped.' during start(). Stopping HubConnection.
I/flutter (14832): HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.
I/flutter (14832): HttpConnection.stopConnection(null) called while in state ConnectionState.disconnecting.
I/flutter (14832): Connection disconnected with error 'Exception: Connection stopped.'.
I/flutter (14832): HubConnection failed to start successfully because of error '{Bad state: Future already completed.toString()}'.

@motasemloubani91
Copy link

anyone has fixed this. The first request in the connection is authorized using the access token in the query string, but the next request are not authorized and keep giving me 401, any help please, we are stuck

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

No branches or pull requests

6 participants