Description
WebSocket configured with pingInterval. Code like this:
Future<WebSocket> wsFuture = WebSocket.connect("wsurl")
.timeout(new Duration(seconds: 15))
.then((ws) {
print("future then called");
ws.pingInterval = new Duration(seconds: 10);
ws.done.then((v) {
print("WS DONE CALLED");
});
ws.listen((d) {
print("WS LISTEN DATA RECEIVED");
}, onError: (e, stack) {
print("WS LISTEN ERROR CALLED $e");
}, onDone: () {
print("WS LISTEN DONE CALLED");
});
}, onError: (e, stack) {
print("future onerror $e");
});
PingInterval documentation says next:
If a ping message is not answered by a pong message from the peer,
the `WebSocket` is assumed disconnected
and the connection is closed with a [WebSocketStatus.GOING_AWAY] close code.
When a ping signal is sent, the pong message must be received within [pingInterval].
If you establish connection to a ws server and sends some data to it via ws.add()
method all works fine - server responses received.
After that If you now emulate 100% loss network condition (for example with Apple Network Link Conditioner tool) after some time (around 2*pingTimeInterval) lambda that passed to ws.done.then()
method called. All fine, except that ws readyState and closeCode doesn't changed like documentation says. But is another bug #33362
In another case, if you establish connection to a ws server, and DO NOT send any data to server via ws.add()
method - problem occur. No matter server sends data to you after connection or not.
If method ws.add()
not used and you emulate 100% loss condition after successfull establishing connection lambda that passed to ws.done.then()
method NOT called like in the first case.
We do not receive any information from pingPong heartbit mechanism that our connection is dead in second case.
Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"
dart:io used for Flutter, but I think is a general problem.