roslib icon indicating copy to clipboard operation
roslib copied to clipboard

Incorrect status when network is unreachable

Open artur-ios-dev opened this issue 5 years ago • 0 comments

As you may be aware there is issue with WebSocketChannel (https://github.com/dart-lang/web_socket_channel/issues/25) that makes it impossible to determine if we are either connected or still connecting to the ws. (maybe want to make another issue for that one to not forget about it once it is fixed on web_socket_channel's side)

  1. Although right now when network is unreachable we are not getting any error while trying to connect it and therefore it says we are connected even though we are not.

  2. This issue might be caused by the incorrect status as mentioned in the first point. While disconnecting/closing the channel there is currently no timeout so when network is unreachable and we want to close the channel/connection we are being stuck with the status connected.

The workaround for the 2nd point could be:

Future<void> close([int code, String reason]) async {
    /// Close listener and websocket.
    await _channelListener?.cancel();
    await Future.any([
      _channel?.sink?.close(code, reason),
      Future.delayed(
        const Duration(milliseconds: 5000), // make the timeout configurable?
      ),
    ]);

    /// Update the connection status.
    status = Status.CLOSED;
    _statusController.add(status);
  }

Might be a better way to handle that though. Maybe we should set status closed regardless of the _channel?.sink?.close(code, reason) outcome? Or should it be actually fixed in the web_socket_channel somehow?

artur-ios-dev avatar Jun 14 '19 12:06 artur-ios-dev