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

Random SocketExceptions: Connection refused / Failed host lookup #2304

Closed
mingjunsiek opened this issue Oct 2, 2024 · 13 comments
Closed

Random SocketExceptions: Connection refused / Failed host lookup #2304

mingjunsiek opened this issue Oct 2, 2024 · 13 comments

Comments

@mingjunsiek
Copy link

mingjunsiek commented Oct 2, 2024

Package

dio

Version

5.7.0

Operating-System

Android, iOS

Adapter

Default Dio

Output of flutter doctor -v

No response

Dart Version

3.5.3

Steps to Reproduce

This issue has been happening since we've updated to Flutter 3.24.0. We've received numerous reports from our users that the app is throwing errors when fetching from the backend.

In our app, we rely on 2 Dio clients which calls 2 different base urls, v1 and v2.
From the error logs shown from the users, calls made to v1 is working well but calls made to v2 always throws either:

  • DioException [connection error]: The connection errored: Failed host lookup: 'x.x.x' This indicates an error which most likely cannot be solved by the library. Error: SocketException: Failed host lookup: 'x.x.x' (OS Error: nodename nor servname provided, or not known, errno = 8)
  • [Dio - ErrorResponse]: DioException [connection error]: The connection errored: Connection refused This indicates an error which most likely cannot be solved by the library. Error: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = x-x.x.x, port = 38772

What I can confirm is that there is indeed internet connection established since concurrently, calls made to v1 was successful but for some reason, calls made to v2 fails. So this has nothing to do with network permissions and network status. Something in the library is somehow not allowing access to our v2 api even though access to v1 is fine.

Expected Result

Should not throw socket exception when making the call to v2

Actual Result

  • DioException [connection error]: The connection errored: Failed host lookup: 'x.x.x' This indicates an error which most likely cannot be solved by the library. Error: SocketException: Failed host lookup: 'x.x.x' (OS Error: nodename nor servname provided, or not known, errno = 8)
  • [Dio - ErrorResponse]: DioException [connection error]: The connection errored: Connection refused This indicates an error which most likely cannot be solved by the library. Error: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = x-x.x.x, port = 38772
@mingjunsiek mingjunsiek added h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 2, 2024
@AlexV525
Copy link
Member

AlexV525 commented Oct 2, 2024

Is this also happening with other implementations? Such as dart:io HttpClient and http Request

@mingjunsiek
Copy link
Author

mingjunsiek commented Oct 2, 2024

Can't really tell unless we swap out our implementation to http and deploy to our users

@AlexV525
Copy link
Member

AlexV525 commented Oct 2, 2024

There should be nothing related to Dio AFAICT.

@AlexV525 AlexV525 added h: need more info Further information is requested i: not related labels Oct 2, 2024
@ziarehmank
Copy link

I can confirm this issue happening in release. Usually starts after device goes to sleep.
I solved my app's issue by migrating to http library.

@AlexV525
Copy link
Member

AlexV525 commented Oct 7, 2024

I can confirm this issue happening in release. Usually starts after device goes to sleep.

@ziarehmank Can you provide a reproducible example and an use case?

@ziarehmank
Copy link

@AlexV525 If I could reproduce it, I would debug the issue myself. But it only happens in release mode.
Crashlytics is full of this errors. We can connect through AnyDesk to the device.
But out app does not send any data to server.

@AlexV525
Copy link
Member

AlexV525 commented Oct 8, 2024

Usually starts after device goes to sleep.

Failed to lookup host and Connection refused should be nothing related to the library itself. However, swapping a new adapter might be helpful in this case.

@kuhnroyal
Copy link
Member

I have noticed this as well but have not found the time to reproduce.

@AlexV525 AlexV525 added h: need extra help Extra help is needed p: dio Targeting `dio` package e: performance Improvements or additions to performance platform: io and removed h: need triage This issue needs to be categorized i: not related labels Oct 9, 2024
@AlexV525 AlexV525 changed the title SocketException: Connection refused / Failed host lookup Random SocketExceptions: Connection refused / Failed host lookup Oct 9, 2024
@AlexV525
Copy link
Member

AlexV525 commented Oct 9, 2024

The only thing I can tell is I got tons of these in our Crashlytics too, but those issues occurred even when using only HttpClient. I've looked at the implementation of the client, it seems we barely have ways to check if a client is closed.

@ziarehmank
Copy link

I am using custom http client. Will this effect the library?.
Also we confirm that this issue start happening after app wakes from sleep.

dio.httpClientAdapter = IOHttpClientAdapter(
    createHttpClient: () {
      final client = HttpClient();
      client.badCertificateCallback =
          (X509Certificate cert, String host, int port) {
        return //hosts;
      };
      return client;
    },
  );

@AlexV525
Copy link
Member

AlexV525 commented Oct 9, 2024

All libraries that based on HttpClient should meet the same issue, which includes package:http.

@ziarehmank
Copy link

@AlexV525 you are right, still happening with http.

@AlexV525
Copy link
Member

Closing based on the above threads.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
@AlexV525 AlexV525 removed h: need extra help Extra help is needed h: need more info Further information is requested p: dio Targeting `dio` package s: bug Something isn't working e: performance Improvements or additions to performance labels Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants