dart-lang / dart-lang/http

Lack of ability to configure connection timeouts

Open
#1,598 18 comments 16 reactions 0 assignees View on GitHub
package:web_socket_channel
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

On mobile connection quality can vary depending on the environment conditions.
if connection is bad for the moment sometimes connecting to a websocket servers can't be established now, and in this situation ConnectionTimeOut exception must thrown.
Actually this exception throws:
`WebSocketChannelException: WebSocketChannelException: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.2.2, port = 56472`
But it take around a 2min before happen.

This is too long for creating a realtime applications with websockets, and sometimes we need to fail faster.

Additionally, this 2 min behaviour is annoying because of issue dart-lang/http#1610 that closed because issue dart-lang/http#1614 and https://github.com/flutter/flutter/issues/18204 created. (connecting and already connected states still not differentiable)

**How this connection timeout can be configured in this package?**

One year ago in issue dart-lang/http#1611 nex3 answered me, that dart io implementation doesn't expose this API. But it is a superficial answer, because:
1) HttpClient has this property
https://api.dartlang.org/stable/2.4.0/dart-io/HttpClient/connectionTimeout.html

2) if we use dart.io or html implementation directly we can use `.timeout` function on futures:
```dart
_wsFuture = WebSocket.connect(backendUrl)
.timeout(Duration(seconds: 15))
.then(_configureWsAfterConnecting);
```

But when using this package I can't manipulate with connection timeout. If connection doesn't establish in acceptable time I can't fail gracefully.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.