Skip to content

dart:io does not use ipv6 on ubuntu 24.04 unless forced #60192

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

Open
noctisbeta opened this issue Feb 23, 2025 · 2 comments
Open

dart:io does not use ipv6 on ubuntu 24.04 unless forced #60192

noctisbeta opened this issue Feb 23, 2025 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team

Comments

@noctisbeta
Copy link

noctisbeta commented Feb 23, 2025

When making http requests to generativelanguage.googleapis.com Dart always goes through ipv4. For some reason, Hetzner's ipv4 addresses for their VPS are blocked. Going through ipv6 works. Other tools (curl, httpie, python) default to ipv6 (but fail when forced to use ipv4 eg. curl -4). Configuring the OS to always prefer ipv6 over ipv4 does not change the dart:io behaviour. The workaround is manually making a request to google's ipv6 address and handling the certificate failure, since this results in a mismatch. Or using a proxy in a custom http client to circumvent the ipv4 block. (this is speculative, but have found others reporting the same block for their ipv4 from Hetzner)

Surely there must be a cleaner way to tell IOClient or HttpClient to use ipv6 instead of ipv4.

This is using

  • Dart 3.7.0 (stable) (None) on "linux_x64"
  • on linux / Linux 6.8.0-52-generic # 53-Ubuntu SMP PREEMPT_DYNAMIC Sat Jan 11 00:06:25 UTC 2025
  • locale is en_US.UTF-8
    on Ubuntu 24.04.1 LTS.

Edit: Is this the culprit, on line 702? Staggered lookup, which checks ipv4 first.

https://github.com/dart-lang/sdk/blob/main/sdk/lib/_internal/vm/bin/socket_patch.dart

Issue referenced: #50868

Edit 2: Since this looks like a dart wide issue, maybe this should be renamed to account for new information. Dart outright refusing to use ipv6 over ipv4 is in contradiction with other tools and works against expectations. This results in very hard to debug and hard to work with scenarios. That is, if I'm understanding this correctly.

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io labels Feb 23, 2025
@brianquinlan
Copy link
Contributor

brianquinlan commented Mar 13, 2025

I've been looking at how other languages deal with this:

Java has a command-line flag or you can can call System.setProperty("java.net.preferIPv4Stack", "true"); programatically.
Python has nothing systematic but you can force IPv4 in urllib3 with requests.packages.urllib3.util.connection.HAS_IPV6 = False
Node has a command-line flag e.g. export NODE_OPTIONS=--dns-result-order=ipv4first or you can call dns.setDefaultResultOrder.

We could have a system like Java/Node where we have a command flag and maybe a static property on Socket. Options could be:

  1. ipv4first (current behavior)
  2. ipv6first
  3. ipv4only (do not use ipv6)
  4. ipv6only (do not use ipv4)
  5. rfc (assume that the DNS server knows what it is doing and use the addresses in the order returned).

This would only apply when connecting to a host by name i.e. if you are connecting via InternetAddress then the family of that address would always be used. Likewise if you are connecting via a string that is interpretable as an address e.g. "127.0.0.1" or "::1".

I think that the awkward part would be testing all of this.

@brianquinlan brianquinlan self-assigned this Mar 18, 2025
@brianquinlan brianquinlan added triaged Issue has been triaged by sub team P2 A bug or feature request we're likely to work on labels Mar 18, 2025
@brianquinlan
Copy link
Contributor

I have a first draft implementation here: https://dart-review.googlesource.com/c/sdk/+/423980/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team
Projects
None yet
Development

No branches or pull requests

3 participants