Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect status when network is unreachable #3

Open
artur-ios-dev opened this issue Jun 14, 2019 · 0 comments
Open

Incorrect status when network is unreachable #3

artur-ios-dev opened this issue Jun 14, 2019 · 0 comments

Comments

@artur-ios-dev
Copy link
Contributor

artur-ios-dev commented Jun 14, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant