Open PhilippS93 opened 1 year ago
Yeah there is this tricky stuff, we should rewrite our ws protocol client, so I will take this and put on my todo list!
@vincenzopalazzo I would love to contribute on this issue if you allow me?
I'm curious if there has been any progress on this? I'm hitting exactly this behavior as well. I've tried the suggested fix and it is still hanging up on the second retry. I'm digging into it here, but I'm curious if anyone has made any progress? It seems strange that something as fundamental as reconnect has been sitting in an non-working state for so long. I wonder what people are using?
I am using
WebSocketLink
for subscription support. The initial connect does work pretty well. When I turn off the internet (autoReconnect is turned on), the reconnect logic in websocket_client.dart uses the reconnect timer invoid onConnectionLost([Object? e]) async
to do the reconnect.When the connection is lost, the following line is called in
onConnectionLost
await _closeSocketChannel();
In this method,, the line
await socketChannel?.sink.close(ws_status.normalClosure);
is executed.This line calls
Future close([int? closeCode, String? closeReason])
insink_completer.dart
which returns thedone
future.In the
done
getter, after the first autoReconnect timeout, the _destinationSink will be null and the lineswill be executed. The resulting future will never complete, because Completer.sync().complete() is never called.
Thus, the client has hung up and will never reconnect.
I have adapted the method like
and now, the reconnect will work again.
To Reproduce (MUST BE PROVIDED)
1) Create a minimal app with websocket support and subscriptions. Set autoReconnect=true 2) start the app, connect the websocket and turn off internet 3) let the websocket reconnect timer run 2 times. 4) the second run will hang up the reconnect, because the future does not complete
Expected behavior The future should complete and reconnect should work
device / execution context