dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.55k forks source link

OS Error: No address associated with hostname, errno = 7 #54580

Open escamoteur opened 7 months ago

escamoteur commented 7 months ago

We see an increasing number of 400 client errors connected with DNS resolution in out Flutter app. Here an example:

Crashed in non-app:
socket_patch.dart in _NativeSocket.startConnect
socket_patch.dart in _RawSocket.startConnect at line 1914
socket_patch.dart in RawSocket.startConnect at line 27
secure_socket.dart in RawSecureSocket.startConnect at line 299
secure_socket.dart in SecureSocket.startConnect at line 77
http_impl.dart in _ConnectionTarget.connect at line 2483
http_impl.dart in _HttpClient._getConnection.connect at line 2926
http_impl.dart in _HttpClient._getConnection at line 2931
http_impl.dart in _HttpClient._openUrl at line 2786
http_impl.dart in _HttpClient.getUrl at line 2628
_http_io.dart in httpGet at line 10 within flutter_svg
In App
loaders.dart in SvgNetworkLoader.prepareMessage at line 436 within flutter_svg
In App
loaders.dart in SvgLoader._load at line 152 within flutter_svg
In App
loaders.dart in SvgLoader.loadBytes.<fn> at line 176 within flutter_svg
In App
cache.dart in Cache.putIfAbsent at line 82 within flutter_svg
In App
loaders.dart in SvgLoader.loadBytes at line 176 within flutter_svg

unfortunately this type of exception doesn't contain any useful information what the underlying reason for that problem is. it would be good if we could get more information if there is no network connection or what could be the problem.

Wie are on latest Flutter verison

codesculpture commented 7 months ago

Seems client doesnt have authorization from the server, since 400 usually returned authentication related errors. Can u make sure that u have appropriate access to the server (for ex: Authorization header)

brianquinlan commented 7 months ago

Also, what URL are you loading?

escamoteur commented 7 months ago

we see it on our normal backend URL watchcrunch.com which is routed via CF. and its no authorization issue because that returns a clear 401 or 403. The current error message is clearly not very helpful

codesculpture commented 7 months ago

I believe dart would give enough information when a http calls fails, but here the reason u are not getting enough information is flutter_svg is not handling errors properly ( i took a glance at the implementation). Well i will get deeper in the dart http error handling and flutter_svg error handling.

escamoteur commented 7 months ago

But Sentry does not receive more information in the underlying exception which means Dart does not forward any additional information Am 1. Feb. 2024, 16:29 +0100 schrieb Aravind @.***>:

I believe dart would give enough information when a http calls fails, but here the reason u are not getting enough information is flutter_svg is not handling errors properly ( i took a glance at the implementation). Well i will get deeper in the dart http error handling and flutter_svg error handling. β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

brianquinlan commented 7 months ago

@escamoteur I'm not sure how to diagnose this. The title of the bug is "OS Error: No address associated with hostname, errno = 7" but I can't see that error anywhere in the text of your issue. Are you seeing more 400 responses in the logs of your servers? Because the "OS Error..." suggests that you can't connect to the server at all.

escamoteur commented 7 months ago

I see different 400s regularly. I think in reality these are connection problems but then I would expect that in an exception and not a message about no adress associated with hostname Am 1. Feb. 2024, 19:11 +0100 schrieb Brian Quinlan @.***>:

@escamoteur I'm not sure how to diagnose this. The title of the bug is "OS Error: No address associated with hostname, errno = 7" but I can't see that error anywhere in the text of your issue. Are you seeing more 400 responses in the logs of your servers? Because the "OS Error..." suggests that you can't connect to the server at all. β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

codesculpture commented 7 months ago

Seems flutter has different implementation of http than dart's http, because dart's http dint throw error when it receives a 400 status code but flutter's http impl is throwing, still looking for the flutter's http implementation

Edit: The above statement is wrong, both flutter and dart using same HTTP Client Implementation which is from dart

codesculpture commented 7 months ago

Hey @escamoteur, i cant reproduce the issue since Flutter Svg throw different error when it receives 400 HttpException (HttpException: Could not get network asset, uri = http://example.com/)

I believe OS err no = 7 could be returned when the app (in emulator) fails to resolve your local IP, do u got these while u are running ur app in emulator and having your svgs in ur backend which is running locally in ur machine?

escamoteur commented 7 months ago

Nope, we get that from Sentry from released versions from our customers

codesculpture commented 7 months ago

So it doesnt seem ur server is returning 400 status code, actually request is not reached ur server so considering that can i know whther these requests being logged in ur server? And also can i know whether ur server is easily reachable? The reason for the whole question the app cant initiate the request to ur server.

Common reasons could be ur client cant resolve ur address, could be ur server url may broken?

escamoteur commented 6 months ago

Nope, that's definitely not the case. IMHO it happens while the app is going into the background or early when resuming or when not network connection exists in all that cases the server isn't reached but the error doesn't say the real reason.

codesculpture commented 6 months ago

To be clear you are seeing 400 number of errors reported in ur sentry and i confused that 400 is a status code of the response actually πŸ˜‚ (i believe @brianquinlan also thought the same), and @escamoteur i think this is the standard error which is been similar across multiple languages, i believe no language would explicitly say "there is no internet connected" while it try to connect to some network. 🀷 And we can just assume these type of errors mostly throwed due to "no internet connection".

codesculpture commented 6 months ago

U may check first is the device is connected to internet, by this https://stackoverflow.com/a/49648870/16690329 🀷 but seems it was very unusual, or u might filter these types of error to being sent to sentry and can save ur sentry limit

tengl commented 5 months ago

I get this error from time to time as well, both in production and on local emulator. But after upgrade to latest Flutter the (Android) app stopped working (in debug, on emulator) and just reported this issue to Sentry like crazy, 100 events per minute or more.

I ran flutter downgrade and reverted some dependency upgrades and now I only get the error now and then, like before. This is what I'm using now.

Doctor summary (to see all details, run flutter doctor -v):
[βœ“] Flutter (Channel stable, 3.13.2, on Pop!_OS 22.04 LTS 6.6.10-76060610-generic, locale en_US.UTF-8)
[βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
[βœ“] Chrome - develop for the web
[βœ“] Linux toolchain - develop for Linux desktop
[βœ“] Android Studio (version 2022.2)
[βœ“] VS Code (version 1.87.2)
[βœ“] Connected device (3 available)
[βœ“] Network resources

β€’ No issues found!

One thing I noted in Sentry was that the Dart runtime was reported as 3.1.0 even when I used Flutter SDK 3.3.0. I don't know what that means.

3.1.0 (stable) (Tue Aug 15 21:33:36 2023 +0000) on \"android_arm\

Anyway, next step will be to upgrade dependencies and test again. If it works, I will update Flutter again and see if the error comes back.

codesculpture commented 5 months ago

@tengl , i suspect this error is happening because of user is accessing some resource (which might be svg) from internet but user may offline and obviously it would throw error, and these errors been stored locally by sentry and being transmitted to sentry console once internet is available.

Can u try to reproduce and check whether this is the problem?

tengl commented 5 months ago

@tengl , i suspect this error is happening because of user is accessing some resource (which might be svg) from internet but user may offline and obviously it would throw error, and these errors been stored locally by sentry and being transmitted to sentry console once internet is available.

Can u try to reproduce and check whether this is the problem?

Sure, I'm accessing our APIs with http.get etc. Sentry caches errors and sends them when network is available. I've downgraded to Flutter 3.13.2, it worked on a real device. And then updated to 3.19.4 again and it still seems to work. I will update dependencies again and check if it still works.

I will also test the emulator again, it shouldn't have had any connection issues because I didn't have any issues on my dev machine, but you never know.

codesculpture commented 5 months ago

@tengl sorry, can i know what meant "works" u are saying.

tengl commented 5 months ago

@tengl sorry, can i know what meant "works" u are saying.

With works I mean that the previous error (errno=7) hasn't appeared again, at least not in the frequency I saw before. I guess it must have entered some error state somehow and wasn't able to get out of it. I still get the error when I enable all exceptions, but it doesn't report to Sentry anymore. I think I get it on every request, but the call stack doesn't reveal any useful information. And the requests seems to go through to the API and back, I don't see any issues in the app anymore.

I'll get back to you if I find out more details about when it occurs.

escamoteur commented 4 months ago

To be clear you are seeing 400 number of errors reported in ur sentry and i confused that 400 is a status code of the response actually πŸ˜‚ (i believe @brianquinlan also thought the same), and @escamoteur i think this is the standard error which is been similar across multiple languages, i believe no language would explicitly say "there is no internet connected" while it try to connect to some network. 🀷 And we can just assume these type of errors mostly throwed due to "no internet connection".

actually it is a 400 status code which is the default client error. the DNS reference on the error message just doesn't make any sense as our domain is clearly reachable. Still thinking that the reported error is wrong. Have you checked where the error message OS Error: No address associated with hostname, errno = 7 is coming from?

escamoteur commented 4 months ago

OK, I got it this time with the excact location where it happens grafik the app is running on an Android emulator on a PC with LAN connection.

I can ping this address just fine grafik

When I try the same host in chrome on the emulator I get an Xml response that clearly shows the address can be resolved, so why do I keep getting theses exceptions? Because of these exceptions it's impossible to leave break on all exceptions active which makes debugging really annoying.

@lrhn this seems indeed like a bug

escamoteur commented 4 months ago

I forgot to add , this is absolutely reproducible

escamoteur commented 4 months ago

Our current Flutter version is

Flutter (Channel stable, 3.19.3, on Microsoft Windows [Version 10.0.19045.4291], locale de-DE)
escamoteur commented 4 months ago

Interesting, while running the app on Windows I got a little different error that might give a hint to the underlying cause grafik From what I found this might happen if there is a DNS entry but not the expected DNS record is there.

The Domain we use has an A and AAAA record. Does the current Dart implementation require any other record types?

escamoteur commented 2 months ago

@brianquinlan maybe this would be better on the HTTP repository? We still get a lot of these even after switching to connet

escamoteur commented 4 weeks ago

The fact that this makes it impossible to use the break on all exceptions makes this bug really annoying @kevmoo could you please look into this?

kevmoo commented 4 weeks ago

@escamoteur – what kind of fix are you looking for?

escamoteur commented 4 weeks ago

I have no idea why te socket implementation throws at at all an exception because the DNS totally valid. I mean it's legit to use an exception for some control flow but it clashes with the option to "break on all exceptions" so as soon as our app does any network calls I cannot enable "break on all exceptions" which is pretty annoying when you try to pinpoint some async exception. So either socket_patch should not throw at all or this part of the SDK should be excluded from the break on all exceptions Am 8. Aug. 2024, 22:18 +0100 schrieb Kevin Moore @.***>:

@escamoteur – what kind of fix are you looking for? β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>