SocketException lookup not handled
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 1.1k
- Forks
- 419
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 8
Description
Hello,
"SocketException (SocketException: Failed host lookup: 'dsfgfdsfgfdgfdgdfg' (OS Error: No address associated with hostname, errno = 7))"
```dart
try {
_pongReceived = true;
var channel = WebSocketChannel.connect(
Uri.parse("ws://dsfgfdsfgfdgfdgdfg:8080/v2/public"));
var stream = channel.stream;
StreamSubscription streamSub;
stream.handleError((e) {
Logger.log(e.toString()); // <--- should be handled here
});
streamSub = stream.listen(
(data) {
var res = DataSubscriptionResponse.fromBuffer(data);
for (var f in responseToEvent) {
var e = f(res);
if (e != null) {
e.emit(res);
break;
}
}
},
cancelOnError: true,
onDone: () {
String closeReason = "";
try {
closeReason = channel.closeReason.toString();
} catch (_) {}
Logger.log("WebSocket done… " + closeReason);
// reconnect !
// _ws = null;
// channel.sink.close();
Future.delayed(Duration(milliseconds: 1000)).then((_) {
streamSub.cancel();
_connect();
});
});
_ws = channel;
Logger.log("WebSocket ok :)");
// renew all subscriptions on connection !
_activeSubscriptions.forEach(subscribe);
} catch (e) {
Logger.log(e.toString()); // <--- OR HERE
}
}
```
I think the culprit is here (io.dart line 64):
```dart
var stream = StreamCompleter.fromFuture(WebSocket.connect(url.toString(),
headers: headers, protocols: protocols)
.then((webSocket) {
webSocket.pingInterval = pingInterval;
channel._webSocket = webSocket;
sinkCompleter.setDestinationSink(_IOWebSocketSink(webSocket));
return webSocket;
}).catchError((error) => throw WebSocketChannelException.from(error))); // I think this is thrown in the wind...
```
I don't mind having to await connect if necessary. But I don't want my app to crash ever....
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at io.dart line 64 and trace WebSocketChannel.connect through WebSocket.connect and StreamCompleter.fromFuture, including the catchError path. Reproduce the failed-host lookup shown in the issue and verify that the exception is observable through the documented connection or stream handling rather than becoming an unhandled error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100