thingsboard / dart_thingsboard_client

ThingsBoard API client library for Dart developers.
BSD 3-Clause "New" or "Revised" License
59 stars 30 forks source link

Problem occurred when using web socket and loosing internet #13

Closed benoit-rolandeau-act closed 8 months ago

benoit-rolandeau-act commented 1 year ago

When listening telemetries and attributes update via the WebSocket. If we loose internet, the following exception happens and can't be managed:

#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:719:35)
#1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1877:26)
#2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
#3      RawSecureSocket.startConnect (dart:io/secure_socket.dart:297:22)
#4      SecureSocket.startConnect (dart:io/secure_socket.dart:77:28)
#5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2482:26)
#6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2924:12)
#7      _HttpClient._getConnection (dart:_http/http_impl.dart:2929:12)
#8      _HttpClient._openUrl (dart:_http/http_impl.dart:2784:12)
#9      _HttpClient.openUrl (dart:_http/http_impl.dart:2622:7)
#10     _WebSocketImpl.connect (dart:_http/websocket_impl.dart:1021:42)
#11     WebSocket.connect (dart:_http/websocket.dart:320:22)
#12     new IOWebSocketChannel.connect (package:web_socket_channel/io.dart:81:28)
#13     connect (package:web_socket_channel/src/_connect_io.dart:15:24)
#14     new WebSocketChannel.connect (package:web_socket_channel/src/channel.dart:115:16)
#15     TelemetryWebsocketService._openSocket (package:thingsboard_client/src/service/telemetry_websocket_service.dart:204:38)
#16     TelemetryWebsocketService._tryOpenSocket (package:thingsboard_client/src/service/telemetry_websocket_service.dart:184:11)
#17     TelemetryWebsocketService._onClose.<anonymous closure> (package:thingsboard_client/src/service/telemetry_websocket_service.dart:292:61)
#18     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#19     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#20     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#21     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

The problem seems to come from the lib you use: WebSocketChannel, as you can see here: https://github.com/dart-lang/web_socket_channel/issues/268

The solution suggested is the following one: https://github.com/flutter/website/issues/8765#issuecomment-1576470328

ikulikov commented 8 months ago

Fixed in ver. 1.0.8. Commit de8aff622af141494f3f8ff860e233ed4f532f56