shamblett / mqtt_client

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

App Crashes on Network Disconnect #374

Closed DariusBotha95 closed 2 years ago

DariusBotha95 commented 2 years ago

Good day, I'm developing an app that uses data from an MQTT broker and displays it to the UI. However, when I started to test the app to see if I can break it, I noticed that when you disconnect the network cable and the client tries to disconnect I run into an Unhandled Exception: SocketException: Connection reset by peer (OS Error: Connection reset by peer, errno = 104) , address = 192.168.0.25, port =44302

This then rethrows and pauses my app in debug mode, however when running the app on a raspberry pi with limited resources (using the flutter-pi engine), the app crashes. I'm assuming that it cannot get past the socket exception. Any idea on how to get past this? maybe a way to ignore the error so the app doesn't crash or any other ideas? Or what part of the connection should I maybe put in a try-catch block - I don't know, I'm quite new to flutter, so anything will be helpful in figuring out how to bypass this.

Thank you, any help is appreciated.

kind regards, Darius

shamblett commented 2 years ago

The exception is thrown by the Dart, or in your case flutter runtime not the client as such. The problem with these exceptions is that for some reason, in some cases they seem to be 'uncatchable'. This has been reported by a few users over the years.

I don't use flutter personally so have no idea what the flutter-pi engine is but you could try putting a try-catch around your main client processing code and see what happens. Other than that maybe other flutter users may be able to help you more. You could also search the closed issues for anything to do with this topic.

DariusBotha95 commented 2 years ago

Thank you @shamblett , I'll try my luck elsewhere then. Thank you for your time