shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

SocketException: Write failed (OS Error: Broken pipe, errno = 32) if app stays in the background for long #441

Closed raphasauer closed 1 year ago

raphasauer commented 1 year ago

Hello! I am having a exception with the mqtt_client library that usually happen when I lock my phone's screen and keep it running on the background. Here are the logs:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: SocketException: Write failed (OS Error: Broken pipe, errno = 32), address = 192.168.1.132, port = 36690
       at _Socket.add(dart:io)
       at MqttServerConnection.send(mqtt_client_mqtt_server_connection.dart:95)
       at MqttConnectionHandlerBase.sendMessage(mqtt_client_mqtt_connection_handler_base.dart:169)
       at MqttConnectionKeepAlive.pingRequired(mqtt_client_mqtt_connection_keep_alive.dart:89)

I believe that the connection is being killed by Android and then the MQTT Server is not being able to ping the broker on my machine via the keep alive function (I could be totally wrong, though).

Is there a fix for this issue? Or it's just the expected behavior of the library in this situation?

shamblett commented 1 year ago

This is a socket exception raised by the flutter runtime, the client has no control over this other than to report it so I guess its normal behaviour.

I know that some users disconnect the client when background is entered and reconnect when they come out of background.

raphasauer commented 1 year ago

I know that some users disconnect the client when background is entered and reconnect when they come out of background.

I think that this is the best approach. I will implement this on my app and post the snippet here for further reference. Thanks for the reply!