Skip to content

Requests to 127.0.0.1 shouldn’t fail just because there’s no v4 address assigned to some other interface #400

@michalrus

Description

@michalrus

I stumbled upon this after creating a systemd service, which started on boot, and called http://127.0.0.1:8094/some-path, which failed with:

Address family for hostname not supported

Screenshot-20190428-154754

This was because I forgot to set After=network.target, so interfaces other than lo 127.0.0.1 didn’t have their IP set (yet).

Because of this line:

NS.addrFlags = [NS.AI_ADDRCONFIG]

… the whole thing failed, according to man getaddrinfo:

       If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4
       addresses are returned in the list pointed to by res only if the
       local system has at least one IPv4 address configured, and IPv6
       addresses are returned only if the local system has at least one IPv6
       address configured.  The loopback address is not considered for this
       case as valid as a configured address.  This flag is useful on, for
       example, IPv4-only systems, to ensure that getaddrinfo() does not
       return IPv6 socket addresses that would always fail in connect(2) or
       bind(2).

But even then, calls to 127.0.0.1 shouldn’t fail.

Probably http-client shouldn’t even be setting AI_ADDRCONFIG. There is really no reason to be using it — e.g. curl doesn’t.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions