Skip to content

Does not catch/report "Network is unreachable" errors on Android #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fernando-s97 opened this issue Feb 11, 2022 · 9 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@fernando-s97
Copy link

fernando-s97 commented Feb 11, 2022

Future<bool> _ping() async {
    try {
      final results = await Ping(ipAddress, count: 4).stream.toList();

      if (results.isEmpty) {
        return false;
      }

      final summary = results.last.summary!;
      final successRate = summary.received / summary.transmitted;
      return successRate > 0.5;
    } catch (e) {
      return false;
    }
  }

The code above always return immediately, doesn't matter if I set the count to 4 or 40. The result is always empty and immediate.

I'm using an Android 11 and the ipAddress is from an iot device (without internet) that I'm connected to.

Also, when using emulated terminals I get "Network is unreachable", but my app can properly communicate with the device.

@point-source
Copy link
Owner

Are you by chance using a language other than English for your Android system/OS primary language? Have you tried debugging or printing out any exceptions that get caught? It seems to me that your code would fail silently in the event of an exception being thrown.

@fernando-s97
Copy link
Author

No. English is the primary language.

I added a breakpoint in both return false; statements, and the only that is reached is the one from if (results.isEmpty).

One thing that I noticed, is that when I also ping with Termux (after connecting with my app), I also get Network is unreachable. Therefore, there's a chance this isn't a bug in the library.

@point-source
Copy link
Owner

Well, I would say it's probably a bug that it isn't returning anything at all. It should at least return or throw the error but I need to figure out how to reproduce this and so far I haven't been able to.

@fernando-s97
Copy link
Author

I could keep this code for some time in my app and try to find what's happening, but I need to know where should I add some logs.

@point-source
Copy link
Owner

point-source commented Feb 16, 2022

A good place to start would be to try the raw command like so:

Future<bool> _ping() async {
    try {
      final ping = Ping(ipAddress, count: 4);

      print(ping.command); // Outputs the command that will be sent to the shell/ping process

      final results = await ping.stream.toList();

      if (results.isEmpty) {
        return false;
      }

      final summary = results.last.summary!;
      final successRate = summary.received / summary.transmitted;
      return successRate > 0.5;
    } catch (e) {
      return false;
    }
  }

Then, copy that command and run it in a terminal emulator on your Android device or emulator and see what it does. If it outputs an error that isn't being caught by dart_ping, then copy that error here as a comment so I can add parsing for it.

@fernando-s97
Copy link
Author

fernando-s97 commented Feb 16, 2022 via email

@fernando-s97
Copy link
Author

The output of ping -O -n -W 2 -i 1 -t 255 -c 4 10.200.116.1 is connect: Network is unreachable

@point-source
Copy link
Owner

point-source commented Feb 21, 2022

Okay. Looks like I need to see why dart_ping isn't catching that error and reporting it back to you. Nonetheless, the fact that you can't ping it due to the network being unreachable is a separate issue between your devices and not related to this package. I will work on getting dart_ping to be more informative about this. Thanks

@point-source point-source changed the title Not working Does not catch/report "Network is unreachable" errors on Android Feb 21, 2022
@point-source point-source added the bug Something isn't working label Feb 21, 2022
@point-source point-source added the help wanted Extra attention is needed label Jan 5, 2023
@ckerens
Copy link
Contributor

ckerens commented Feb 1, 2023

I was able to reproduce this error by statically assigning an IP address outside of the subnet. The errors I get are Destination Host Unreachable or Network is unreachable depending on whether or not the Wi-Fi is connected.

I can submit a PR for this. I'll add new ErrorType.unreachable and the regex to the parser.

ckerens added a commit to ckerens/dart_ping that referenced this issue Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants