web_socket_client icon indicating copy to clipboard operation
web_socket_client copied to clipboard

fix: timeout does not have any effect

Open aytunch opened this issue 2 years ago • 0 comments

Description

I am not sure if I understand the function of timeout yet so if this is not a bug accept my apologies. I think timeout means, if client can not connect to the WS server for timeout duration, the client will not keep on trying to connect anymore. It will give up!

Steps To Reproduce

When I don't supply a timeout in the WS, it should use the default timer which is 60 seconds.

/// The default connection timeout duration.
const _defaultTimeout = Duration(seconds: 60);

I shut down my server while client is connected Client connection becomes Reconnecting I wait for 4 minutes and run the server again Client connection becomes Reconnected

Expected Behavior

Expected behavior would be after the timeout, client should be Disconnected and even when the server is back up again, it should not try to connect to it.

Additional Context

In web_socket.dart the onTimeout callback is not used. So I don't know if the timeout has any effect or not.

      final ws = await connect(
        _uri.toString(),
        protocols: _protocols,
        pingInterval: _pingInterval,
      ).timeout(_timeout);  //there is an optional onTimeout

Future<Stream<dynamic>> timeout(Duration timeLimit, {FutureOr<Stream<dynamic>> Function()? onTimeout})

Lastly, when timeout occurs, will the client get a Disconnect with a timeout reason and code?

EDIT: I realized that you are using try catch to catch timeout cases. And you are calling reconnect over and over again. If this is the expected behavior then accepting a numberOfReconnects int might be very useful imo.

aytunch avatar Jan 27 '23 17:01 aytunch