braverhealth / phoenix-socket-dart

Cross-platform and stream-based implementation of Phoenix Sockets
https://pub.dev/packages/phoenix_socket
BSD 3-Clause "New" or "Revised" License
74 stars 37 forks source link

Reconnection handling ignores reconnection delay #6

Closed hamann closed 3 years ago

hamann commented 3 years ago

Follow-up to #5

When the backend stops, a reconnect occurs every few milliseconds until backend is up again.

flutter: 2020-10-26 17:38:28.850366 FINE phoenix_socket.socket - [phoenix_socket] Heartbeat completed
flutter: 2020-10-26 17:38:58.850027 FINE phoenix_socket.socket - [phoenix_socket] Heartbeat completed
flutter: 2020-10-26 17:39:17.142897 INFO phoenix_socket.socket - Socket closed with reason  and code 1005
flutter: 2020-10-26 17:39:17.143592 FINE phoenix_socket.socket - Trigger channel exceptions on 1 channels
flutter: 2020-10-26 17:39:17.144857 FINE phoenix_socket.channel.user - Receiving error on channel
### PhoenixException: PhoenixException: socket closed
flutter: 2020-10-26 17:39:17.146353 WARNING phoenix_socket.channel.user - Got error on channel
### PhoenixException: PhoenixException: socket closed
flutter: 2020-10-26 17:39:17.458004 SEVERE phoenix_socket.socket - Error on socket
### WebSocketChannelException: WebSocketChannelException: WebSocketChannelException: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:4000/socket/websocket?api_token=SFMyNTY.g2gDYQFuBgBrftRcdQFiAAFRgA.E1_gPO_lHXBwZmeOoIad4QUAXB2a_8rn0VwInqncz5k&vsn=2.0.0
#0      new IOWebSocketChannel._withoutSocket.<anonymous closure>
package:web_socket_channel/io.dart:84
#1      _invokeErrorHandler (dart:async/async_error.dart:16:24)
#2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:282:9)
#3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:161:13)
#4      _rootRunBinary (dart:async/zone.dart:1214:47)
#5      _CustomZone.runBinary (dart:async/zone.dart:1107:19)
#6      _CustomZone.runBinaryGuarded (dart:async/zone.dart:1013:7)
#7      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:376:15)
#8      _Bufferin<…>
flutter: 2020-10-26 17:39:17.458627 FINE phoenix_socket.socket - Trigger channel exceptions on 1 channels
flutter: 2020-10-26 17:39:17.458765 FINE phoenix_socket.channel.user - Receiving error on channel
### PhoenixException: WebSocketChannelException: WebSocketChannelException: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:4000/socket/websocket?api_token=SFMyNTY.g2gDYQFuBgBrftRcdQFiAAFRgA.E1_gPO_lHXBwZmeOoIad4QUAXB2a_8rn0VwInqncz5k&vsn=2.0.0
flutter: 2020-10-26 17:39:17.459173 INFO phoenix_socket.socket - Socket closed with reason null and code null
flutter: 2020-10-26 17:39:17.459390 FINE phoenix_socket.socket - Trigger channel exceptions on 1 channels
flutter: 2020-10-26 17:39:17.459546 FINE phoenix_socket.channel.user - Receiving error on channel
### PhoenixException: PhoenixException: socket closed
flutter: 2020-10-26 17:39:17.460272 SEVERE phoenix_socket.socket - [phoenix_socket] Heartbeat message failed with error
### WebSocketChannelException: WebSocketChannelException: WebSocketChannelException: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:4000/socket/websocket?api_token=SFMyNTY.g2gDYQFuBgBrftRcdQFiAAFRgA.E1_gPO_lHXBwZmeOoIad4QUAXB2a_8rn0VwInqncz5k&vsn=2.0.0
#0      new IOWebSocketChannel._withoutSocket.<anonymous closure>
package:web_socket_channel/io.dart:84
#1      _invokeErrorHandler (dart:async/async_error.dart:16:24)
#2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:282:9)
#3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:161:13)
#4      _rootRunBinary (dart:async/zone.dart:1214:47)
#5      _CustomZone.runBinary (dart:async/zone.dart:1107:19)
#6      _CustomZone.runBinaryGuarded (dart:async/zone.dart:1013:7)
#7      _BufferingStreamSubscription._sendError.sendError (dart:async/strea<…>
flutter: 2020-10-26 17:39:17.460733 FINE phoenix_socket.socket - Trigger channel exceptions on 1 channels
flutter: 2020-10-26 17:39:17.462510 FINE phoenix_socket.channel.user - Receiving error on channel
### PhoenixException: WebSocketChannelException: WebSocketChannelException: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:4000/socket/websocket?api_token=SFMyNTY.g2gDYQFuBgBrftRcdQFiAAFRgA.E1_gPO_lHXBwZmeOoIad4QUAXB2a_8rn0VwInqncz5k&vsn=2.0.0
flutter: 2020-10-26 17:39:17.462920 INFO phoenix_socket.socket - Socket open
flutter: 2020-10-26 17:39:17.464868 WARNING phoenix_socket.push.user - Catched error for push 24
### PhoenixException: PhoenixException: socket closed
flutter: 2020-10-26 17:39:17.763120 INFO phoenix_socket.socket - Socket open
flutter: 2020-10-26 17:39:17.768263 SEVERE phoenix_socket.socket - Error on socket
matehat commented 3 years ago

I think I fixed the issue in master, can you try @hamann ?

hamann commented 3 years ago

@matehat You did, thanks a lot! 🎉

akashvibhute commented 3 years ago

@matehat I still get this issue. If my phoenix server is stopped, the client keeps on reconnecting every millisecond if I don't pass any value to reconnectDelays. If I pass a list of Durations, only the first duration is taken and it keeps on reconnecting with the same interval instead of increasing as per the list. On flutter 2.2 and latest version of the package. I thought this was an issue with riverpod providers, but I can reproduce it with initializing the socket connection directly in the main method itself or as a global variable imported to join a channel.

matehat commented 3 years ago

@akashvibhute can you reopen a new issue and report stacktraces and such?

akashvibhute commented 3 years ago

Yes, I will create new issue with logs.