Skip to content

SocketException: Failed host lookup #53331

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

Closed
NeroThroN opened this issue Aug 24, 2023 · 18 comments
Closed

SocketException: Failed host lookup #53331

NeroThroN opened this issue Aug 24, 2023 · 18 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report library-io P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@NeroThroN
Copy link

Copied from flutter issue #132912

Steps to reproduce

Just make a network request.

For example, using the basic http package.

Also relevant when using other packages, such as Dio.
The same error, and in the same versions of Flutter.

Therefore, I think they have the same root.

The bug is very critical, as already many communities of various applications complain about it.

I have given the simplest code example below.
The main essence is in the line:

await http.get(Uri.parse('https://flutter.dev'));

This request throws an exception:
SocketException (SocketException: Failed host lookup: 'flutter.dev' (OS Error: ... , errno = 11004))

This error appears on ANY host of the many that I have tried.
That is, the problem is not in a particular host.

This problem is relevant for Windows (which discards many other similar problems that can be found on the Internet and which are associated with missing permissions on the Android system). It's not that problem.

I've reproduced this bug in the latest master as well as in the latest stable release.
On the Internet people advise to downgrade Flutter to version 3.10.5, where this problem does not reproduce. I personally haven't tried it yet, but I suspect that all versions after 3.10.5 have this bug.
But downgrading to that version is not an option for me anyway.

Please fix this bug as soon as possible.
Yes, this exception is skippable, but it creates debugging inconvenience in many cases.
Moreover, this problem is relevant for many.

Thank you!

Expected results

No exception

Actual results

This request throws an exception:
SocketException (SocketException: Failed host lookup: 'flutter.dev' (OS Error: ... , errno = 11004))

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> _test() async {
    try {
      await http.get(Uri.parse('https://flutter.dev'));
    } catch (ex) {
      // ignore: use_build_context_synchronously
      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text('Result'),
            content: Text(
              ex.toString(),
            ),
            actions: <Widget>[
              TextButton(
                child: const Text('Ok'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        },
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: _test,
        child: const Icon(Icons.error),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
Is there an existing issue for this?

    I have searched the [existing issues](https://github.com/flutter/flutter/issues)
    I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

Steps to reproduce

Just make a network request.

For example, using the basic http package.

Also relevant when using other packages, such as Dio.
The same error, and in the same versions of Flutter.

Therefore, I think they have the same root.

The bug is very critical, as already many communities of various applications complain about it.

I have given the simplest code example below.
The main essence is in the line:

await http.get(Uri.parse('https://flutter.dev'));

This request throws an exception:
SocketException (SocketException: Failed host lookup: 'flutter.dev' (OS Error: ... , errno = 11004))

This error appears on ANY host of the many that I have tried.
That is, the problem is not in a particular host.

This problem is relevant for Windows (which discards many other similar problems that can be found on the Internet and which are associated with missing permissions on the Android system). It's not that problem.

I've reproduced this bug in the latest master as well as in the latest stable release.
On the Internet people advise to downgrade Flutter to version 3.10.5, where this problem does not reproduce. I personally haven't tried it yet, but I suspect that all versions after 3.10.5 have this bug.
But downgrading to that version is not an option for me anyway.

Please fix this bug as soon as possible.
Yes, this exception is skippable, but it creates debugging inconvenience in many cases.
Moreover, this problem is relevant for many.

Thank you!
Expected results

No exception
Actual results

This request throws an exception:
SocketException (SocketException: Failed host lookup: 'flutter.dev' (OS Error: ... , errno = 11004))
Code sample
Code sample

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> _test() async {
    try {
      await http.get(Uri.parse('https://flutter.dev'));
    } catch (ex) {
      // ignore: use_build_context_synchronously
      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text('Result'),
            content: Text(
              ex.toString(),
            ),
            actions: <Widget>[
              TextButton(
                child: const Text('Ok'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        },
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: _test,
        child: const Icon(Icons.error),
      ),
    );
  }
}

Screenshots or Video

No response
Logs

No response
Flutter Doctor output
Doctor output

[✓] Flutter (Channel master, 3.14.0-8.0.pre.17, on Microsoft Windows [Version 10.0.22621.2134], locale ru-UA)
    • Flutter version 3.14.0-8.0.pre.17 on channel master at C:\SDK\Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6f227c0784 (2 days ago), 2023-08-18 19:04:15 -0700
    • Engine revision f4bffdcf85
    • Dart version 3.2.0 (build 3.2.0-87.0.dev)
    • DevTools version 2.26.1

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\SDK\Android
    • Platform android-33-ext5, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\Chromium\chrome

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34009.444
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.6+0-b2043.56-9586694)

[✓] VS Code (version 1.81.1)
    • VS Code at C:\Users\Yegor\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.70.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2134]
    • Chrome (web)      • chrome  • web-javascript • unknown
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 115.0.1901.203

[✓] Network resources
    • All expected network resources are available.
@koodimetsa
Copy link

Possible reason: flutter/flutter#132912 (comment)

@NeroThroN
Copy link
Author

Possible reason: flutter/flutter#132912 (comment)

The behavior changed between 3.10.x (3.10.5 precisely) and 3.13.0 without an announcement about breaking changes so it shouldn't be a migration on the developer side to fix it. Especially since you can't change the configuration of certain servers when you don't have control over them.

I've found this comment which details in a more precise way the problem: issue #4695

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Aug 25, 2023
@a-siva a-siva added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Aug 25, 2023
@a-siva
Copy link
Contributor

a-siva commented Aug 25, 2023

This seems related to #53334

@a-siva
Copy link
Contributor

a-siva commented Aug 25, 2023

@NeroThroN are you seeing this only on Windows?
I tried running your simple example on Linux and do not see the exception.

@a-siva
Copy link
Contributor

a-siva commented Aug 25, 2023

@NeroThroN do you observe this exception only when running under the debugger or do you see it even on a regular run outside the debugger ?

@NeroThroN
Copy link
Author

This seems related to #53334

Yes indeed, I think it is indeed related

@NeroThroN are you seeing this only on Windows? I tried running your simple example on Linux and do not see the exception.

Based on my scenarios, I have the issue in multiple scenarios:

(Development OS > Target Device => result)

  • Linux (Fedora 38) > Linux (Fedora 38) => Problem occurs
  • Linux (Fedora 38) > Old Android (Android 9) => Problem does not occur
  • Windows 11 > New Android (Android 13) => Problem occurs

@NeroThroN do you observe this exception only when running under the debugger or do you see it even on a regular run outside the debugger ?

I only had the problem while in debug mode. Without debugger mode or even in release mode, the application works fine.
I also tested the first of the above scenarios (Linux > Linux) using Android Studio instead of vscode, and the problem did not appear.

@azizkazdal
Copy link

I have same issue on window + android studio in debug. Running Android 13 at emulator.
Did not try in release mode. Downgraded to flutter 3.10.6

@andynewman10
Copy link

andynewman10 commented Aug 27, 2023

I can repro this issue with

  • Flutter 3.13.1,
  • VS code 1.81 on Windows. 'All exceptions' is not selected, 'Uncaught exceptions' is selected. Debug mode is 'Just my code'.
  • targetting Android 7.1.1
  • the Android device has both IPv4 and IPv6 addresses on my LAN.

The exception is thrown and the debugger stops when making an https (secure) request to a IPv4-only internet (public) host, not supporting IPv6.

The debugger does not stop (meaning the exception is not thrown?) when making an http request to an IPv4-only LAN (not internet) host.

I understand that the dart:io code tries IPv4 connections first, based on this reply from Brian Quinlan @brianquinlan :

#50868 (comment)

I modified the socket connection logic to favor IPv4 connections over IPv6 connections, as we already did on iOS.

(I am assuming that the http package has identical behavior (on Android and iOS)).

Because of this, it is a bit surprising that the debugger stops when dealing with IPv4-only internet addresses.

@a-siva
Copy link
Contributor

a-siva commented Aug 29, 2023

I only had the problem while in debug mode. Without debugger mode or even in release mode, the application works fine. I also tested the first of the above scenarios (Linux > Linux) using Android Studio instead of vscode, and the problem did not appear.

Based on this I am marking this as a duplicate of #53334

@cetindogu
Copy link

any solution yet?

@a-siva
Copy link
Contributor

a-siva commented Apr 1, 2024

@cetindogu this issue is closed, if you are encountering an issue please open a new issue with instructions on how to reproduce the problem you are encountering.

@astheras
Copy link

astheras commented Apr 2, 2024

i have faced this problem in all my projects for a long time, which work with the API. I can't uncheck "all exceptions" because I need to see app exceptions inside try catch
I am very much looking forward to the decision

@a-siva
Copy link
Contributor

a-siva commented Apr 2, 2024

@astheras a fix for the above problem was landed a while back which problem are you still facing ?

@joabsantos
Copy link

I am still facing the same issue, flutter version : 3.10.6.

It is not easy to reproduce, but the way I was able to do it was, by minimizing the application for a while, re-opening it, and trying to perform any 'http calls' inside of the app for some time.

I am using Dio Package, and whenever this problem occurs, my interceptors are not getting hit and all HTTP calls automatically get 401 without going into the interceptors where I inject the auth token. it only works again If I stop the app and restart it.

@scottynoshotty
Copy link

I think I am seeing an issue related to this.

I have a Global external application load balancer exposing a HTTP ip v4 url. My Flutter app connects to this using NetworkImage to load images. This is working well for most users most of the time. I have some users somehow getting into a state where all images stop loading. These are very small images (~10KB) which cannot be loaded on a very fast cell signal. When the user switches over to WIFI the images start loading again.

@bdezso
Copy link

bdezso commented Jun 22, 2024

I think I am seeing an issue related to this.

I have a Global external application load balancer exposing a HTTP ip v4 url. My Flutter app connects to this using NetworkImage to load images. This is working well for most users most of the time. I have some users somehow getting into a state where all images stop loading. These are very small images (~10KB) which cannot be loaded on a very fast cell signal. When the user switches over to WIFI the images start loading again.

I have users too who got failed lookup

@decioschmitt
Copy link

I recently encountered an error like this where the problem was with the server's digital certificate. The certificate I was using appeared as ok in the browser but the app wouldn't connect. I renewed the server's certificate and the app started connecting again. I only realized this because the error started appearing after the server's certificate was changed.

@Wdestroier
Copy link

i have faced this problem in all my projects for a long time, which work with the API. I can't uncheck "all exceptions" because I need to see app exceptions inside try catch

Thanks, I always forget I need to uncheck "All Exceptions" when running the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report library-io P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests