Skip to content

MDnsClient throws uncatched exception when Android device disconnected from network #165482

@alexander-irion

Description

@alexander-irion

Steps to reproduce

  1. Disable WLAN in Android device
  2. Create and start MDnsClient:
final MDnsClient client = MDnsClient();
await client.start();
  1. Lookup for a service type:
List<PtrResourceRecord> ptrRecords = await client.lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer("_workstation._tcp.local")).toList();

Expected results

No exception happens, or exception can be catched with try-catch block around client.lookup.

Actual results

The following unhandled exception occurs, which leads the application to stop when running from debugger. The exception can not be handled with a try-catch block around MDnsClient.lookup.

E/flutter (19343): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: SocketException: Send failed (OS Error: Network is unreachable, errno = 101), address = 0.0.0.0, port = 5353
E/flutter (19343): #0      _NativeSocket.send (dart:io-patch/socket_patch.dart:1512:34)
E/flutter (19343): #1      _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:3070:15)
E/flutter (19343): #2      MDnsClient.lookup (package:multicast_dns/multicast_dns.dart:212:22)
E/flutter (19343): #3      main (package:bug/main.dart:10:22)
E/flutter (19343): <asynchronous suspension>

Code sample

Code sample
// ignore_for_file: avoid_print

import 'package:multicast_dns/multicast_dns.dart';

void main() async {
  final MDnsClient client = MDnsClient();
  await client.start();
  try {
    List<PtrResourceRecord> ptrRecords =
        await client.lookup<PtrResourceRecord>(ResourceRecordQuery.serverPointer("_workstation._tcp.local")).toList();
    print(ptrRecords);
  } catch (e) {
    print("Error: $e");
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
flutter run
Launching lib/main.dart on Lenovo YT X705F in debug mode...
Running Gradle task 'assembleDebug'...                           1.558ms
✓ Built build/app/outputs/flutter-apk/app-debug.apk
Installing build/app/outputs/flutter-apk/app-debug.apk...           4,9s
I/flutter (20555): [IMPORTANT:flutter/shell/platform/android/android_context_vk_impeller.cc(60)] Using the Impeller rendering backend (Vulkan).
E/flutter (20555): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: SocketException: Send failed (OS Error: Network is unreachable, errno = 101), address = 0.0.0.0, port = 5353
E/flutter (20555): #0      _NativeSocket.send (dart:io-patch/socket_patch.dart:1512:34)
E/flutter (20555): #1      _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:3070:15)
E/flutter (20555): #2      MDnsClient.lookup (package:multicast_dns/multicast_dns.dart:212:22)
E/flutter (20555): #3      main (package:bug/main.dart:10:22)
E/flutter (20555): <asynchronous suspension>
E/flutter (20555): 
Syncing files to device Lenovo YT X705F...                           4ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Lenovo YT X705F is available at: http://127.0.0.1:35435/_2E3P-WqK_U=/
I/flutter (20555): []
D/ProfileInstaller(20555): Installing profile for com.example.bug

Application finished.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.0, on Ubuntu 24.04.1 LTS 6.8.0-55-generic, locale de_DE.UTF-8) [110ms]
    • Flutter version 3.29.0 on channel stable at /home/airion/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (vor 5 Wochen), 2025-02-10 12:48:41 -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [1.310ms]
    • Android SDK at /home/airion/Android/Sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /snap/android-studio/161/jbr/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [14ms]
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop [153ms]
    • Ubuntu clang version 18.1.3 (1ubuntu1)
    • cmake version 3.28.3
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2024.1) [12ms]
    • Android Studio at /snap/android-studio/161
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.96.4) [10ms]
    • VS Code at /usr/share/code
    • Flutter extension version 3.106.0

[✓] Connected device (3 available) [186ms]
    • Lenovo YT X705F (mobile) • HGAJG912 • android-arm64  • Android 10 (API 29)
    • Linux (desktop)          • linux    • linux-x64      • Ubuntu 24.04.1 LTS 6.8.0-55-generic
    • Chrome (web)             • chrome   • web-javascript • Google Chrome 132.0.6834.110

[✓] Network resources [282ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listfound in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: multicast_dnsThe mdns packagepackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions