Eternali / roslib

ROS interface library in Dart.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect status when network is unreachable

artur-ios-dev opened this issue · comments

commented

As you may be aware there is issue with WebSocketChannel (dart-lang/web_socket_channel#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?