Skip to content
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

SocketException: Failed host lookup #1008

Closed
yegor-pelykh opened this issue Aug 20, 2023 · 9 comments
Closed

SocketException: Failed host lookup #1008

yegor-pelykh opened this issue Aug 20, 2023 · 9 comments
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@yegor-pelykh
Copy link

yegor-pelykh commented Aug 20, 2023

Steps to reproduce

Just make a network request using the 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.
@yegor-pelykh yegor-pelykh added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Aug 20, 2023
@mihalycsaba
Copy link

mihalycsaba commented Aug 21, 2023

I have the same problem with 3.13.

Response response = await get(Uri.parse(url), headers: <String,String> {'Cookie': 'PHPSESSID=${prefs.getString('sessid')}'});

HandshakeException (HandshakeException: Connection terminated during handshake)

Sometimes SocketException, but anyway looks like this package doesn't work at all with the latest stable. Works with 3.10.6

@mihalycsaba
Copy link

Also it looks like it's not just a skippable exception, it breaks a few things, for example I can't load images with cached_network_image even If I step over exceptions. Anyway I have downgraded to 3.10.6, please give some feedback when I can return to stable.

@yegor-pelykh
Copy link
Author

I also opened an issue like this in the flutter repository:
#flutter/flutter#132912

@riverscuomo
Copy link

I'm getting this on 3.13 also.

@brianquinlan
Copy link
Collaborator

I think that this is a duplicate of dart-lang/sdk#53334

@GaneshTamang
Copy link

GaneshTamang commented Sep 4, 2023

Same here run without debugging works fine but when debugging mode socket error

@Wizzel1
Copy link

Wizzel1 commented Sep 10, 2023

Same here on Version 3.13.3

@yasinguness
Copy link

Can anyone solve the problem? Does anyone have the same problem with Dio?

@brianquinlan
Copy link
Collaborator

This is a Dart issue, not a package:http issue so package:dio won't help either :-(

The next hotfix releases of Dart and Flutter should happen tomorrow (fingers crossed) and will fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants