Skip to content

ws.done called only if you at least once used ws.add() method #33379

Open
@nailgilaziev

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.

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions