-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
some errors can't be handled in IOWebSocketChannel.connect #1619
Comments
Hi, did you found some solution? |
yes, my workaround is to create a
Then I wrap this in a try-catch, so I can catch |
I got it. Thanks. |
I have the same problem, but I thought that the exception should be handled in
But nothing happends. |
@roger357, the following way works for me:
I don't know if it is working because I have a StreamSubscription or whether it simply is an additional step. |
I was facing same issue I believe IOWenSocketChannel would have similar approach to await and catch error
|
While @adityabansalx solution works, I find it weird that adding |
Hey @Jalmoud2, what I understood is, calling connect gives a channel immediately, and initiates the connection to the socket server which may fail. e.g. request timeout. compare it to async Http request. The point is channel connection and stream are different things. you can get a Sink or a Stream from the channel and they can have errors during their own functioning |
@Jalmoud2, I think putting it this way, would help understand the behavior.
|
Thanks to you guys comments, I found what I was looking for and here it is:
EDIT: Added reconnect duration each time it failed, until a maximum of 60 seconds (import 'dart:math' as math;)... Reset the duration to 3 on connection succes.
|
Copied from flutter/flutter#21076
IOWebSocketChannel.connect
suffers from the problem described here:https://www.dartlang.org/guides/libraries/futures-error-handling#potential-problem-failing-to-register-error-handlers-early
When I use
connect
with a URL that can't be resolved (e.g. by having my wifi turned off), then I get an exception that can't be caught bychannel.stream.handleError(onError)
.All exceptions should be handleable by
stream.handleError
, particularly as this is what the docs promise: "If there's an error connecting, the channel's stream emits a WebSocketChannelException wrapping that error and then closes."ref: https://docs.flutter.io/flutter/web_socket_channel.io/IOWebSocketChannel/IOWebSocketChannel.connect.html
The text was updated successfully, but these errors were encountered: