-
Notifications
You must be signed in to change notification settings - Fork 364
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
web_socket_channel 2.3.0 - IOWebSocketChannel.connect Doesn't Handle SocketException #1519
Comments
Same issue with
It's impossible to handle the exception. You'll get |
Having the same issue, to me being a Timeout whenever I hot restart. |
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 48482 #0 _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:694:35) I deliberately have the server down, and have the client retry to tests things out. It should have handle it gracefully. Platform I use is linux Doctor summary (to see all details, run flutter doctor -v): I believe this is thrown from io.dart line 117
But that part of the code from web_scoket_channel didn't change recently (but so am I) |
I've just tested web_socket_channel 2.2.0 and 2.3.0 and both have the same issue. I believe why we're now seeing this bug is because of iOS16 (except maybe the linux guy), from what I can tell, it reclaims the port after ~1 minute in background (unless something has changed somewhere else in my setup which I've not accounted for). Work around 1 (create websocket directly)
Work around 2 (guarded zone)
|
Thanks @MousyBusiness This is what I end up using
|
As of 2.3.0, the correct error handling formulation is: final channel = WebSocketChannel.connect(Uri.parse('ws://example.com'));
try {
await channel.ready;
} on SocketException catch (e) {
// Handle the exception.
} on WebSocketChannelException catch (e) {
// Handle the exception.
} I have a PR out to clarify this: dart-lang/web_socket_channel#272 And sorry for not managing this change better. |
When I close the internet connection to test what happens in onDone method,
Trying to handle exception but it doesn't handle;
This code works on web_socket_channel version 2.2.0 (even I don't need to use) but on version 2.3.0 I'm getting:
The text was updated successfully, but these errors were encountered: