twosigma / twosigma/nsncd

IPv6 is inconsistent with getaddrinfo

Open
#157 11 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
78
Forks
22
Avg merge
2d 3h
Merged PRs (30d)
13

Description

Sometimes addresses `*.local` only return IPv6 addresses.

This is a major issue when using `.local` mDNS, since you apparently [have to specify the interface when using link-local addresses](https://networkengineering.stackexchange.com/questions/52581/ssh-connect-to-host-myserver-port-22-invalid-argument-intermittent-ipv6-l).

But to be fair it's happens pretty randomly.

Sometimes running `dog myothermachine.local` (requesting the A record for `myothermachine.local` from `127.0.0.53`) helps, but doesn't currently.

Here's a Python script to reproduce it:
```py
# set lan_device_1 and lan_device_2

import socket
import subprocess
import time

def check(comment, hostname):
print(f' {comment}')
for tup in socket.getaddrinfo(hostname, 443, type=socket.SOCK_STREAM):
(family, type, proto, canonname, sockaddr) = tup
type_str = 'IPv6' if family == socket.AF_INET6 else 'IPv4'
print(' ', type_str)

def check_all():
check('localhost', 'localhost')
check('own hostname', socket.gethostname() + '.local')
check('google.com', 'google.com')
check('LAN device 1', lan_device_1)
check('LAN device 2', lan_device_2)

check_all()

import sys
if len(sys.argv) > 1 and sys.argv[1] == 'immutable':
sys.exit(0)

print('stopping nsncd')
subprocess.run(['sudo', 'systemctl', 'stop', 'nscd'], check=True)

check_all()

print('starting nsncd')
subprocess.run(['sudo', 'systemctl', 'start', 'nscd'], check=True)

print('restarting the process')
# even sleep doesn't help here. I'm guessing glibc doesn't reconnect to nsncd
subprocess.run([sys.executable, sys.argv[0], 'immutable'], check=True)
```

```console
$ python main.py
localhost
IPv6
IPv4
own hostname
IPv4
IPv6
google.com
IPv4
IPv6
LAN device 1
IPv4
IPv6
LAN device 2
IPv6
stopping nsncd
localhost
IPv6
IPv4
own hostname
IPv4
IPv6
google.com
IPv4
IPv6
LAN device 1
IPv4
IPv6
LAN device 2
IPv4
IPv6
starting nsncd
restarting the process
localhost
IPv6
IPv4
own hostname
IPv4
IPv6
google.com
IPv4
IPv6
LAN device 1
IPv6
LAN device 2
IPv6
```

Example of ssh not working

```console
$ ssh myothermachine.local
ssh: connect to host myothermachine.local port 22: Invalid argument
$ ssh myothermachine.local -v
[...]
debug1: Connecting to myothermachine.local [fe80::1234] port 22.
debug1: connect to address fe80::1234 port 22: Invalid argument
ssh: connect to host myothermachine.local port 22: Invalid argument
```

### System info
```
x86_64-linux
Linux 6.14.0, NixOS, 25.05 (Warbler), 25.05.20250402.2c8d3f4
systemd 257.3
GNU libc 2.40
nsncd 1.5.1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.