Skip to content

Commit 89d3d46

Browse files
nGolineclaude
andcommitted
connectd/tests: fix test_announce_and_connect_via_dns on macOS
Two issues caused this test to fail or produce BROKEN log messages on macOS: 1. macOS does not include 'localhost.localdomain' in /etc/hosts by default, so the test's DNS-resolve step fails immediately. Skip with a clear message if the hostname is not resolvable. 2. On macOS/BSD, AI_ADDRCONFIG is implemented by opening temporary probe sockets to test IPv4/IPv6 connectivity. Those sockets are not registered with the io framework, so dev_report_fds() flags them as unowned (BROKEN). Guard AI_ADDRCONFIG with #ifndef __APPLE__ so Linux keeps the optimization while macOS avoids the fd-leak. Changelog-None Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 73825bc commit 89d3d46

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

connectd/connectd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,13 @@ static void try_connect_one_addr(struct connecting *connect)
11341134
hints.ai_socktype = SOCK_STREAM;
11351135
hints.ai_family = AF_UNSPEC;
11361136
hints.ai_protocol = 0;
1137+
/* AI_ADDRCONFIG speeds up connects on single-stack hosts by
1138+
* pruning unreachable address families. Skip on macOS/BSD
1139+
* where it opens temporary probe sockets that confuse our
1140+
* fd-leak checker. */
1141+
#ifndef __APPLE__
11371142
hints.ai_flags = AI_ADDRCONFIG;
1143+
#endif
11381144
gai_err = getaddrinfo((char *)addr->u.wireaddr.wireaddr.addr,
11391145
tal_fmt(tmpctx, "%d",
11401146
addr->u.wireaddr.wireaddr.port),

tests/test_gossip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ def test_announce_and_connect_via_dns(node_factory, bitcoind):
202202
- --disable-dns is needed so the first node does not announce 127.0.0.1 itself.
203203
- 'dev-allow-localhost' must not be set, so it does not resolve localhost anyway.
204204
"""
205+
# localhost.localdomain is not present in /etc/hosts on macOS by default.
206+
# See https://github.com/ElementsProject/lightning/issues/9012
207+
try:
208+
socket.getaddrinfo('localhost.localdomain', 12345, 0, socket.SOCK_STREAM)
209+
except socket.gaierror:
210+
pytest.skip("localhost.localdomain not resolvable; add '127.0.0.1 localhost.localdomain' to /etc/hosts")
211+
205212
opts1 = {'disable-dns': None,
206213
'announce-addr': ['dns:localhost.localdomain:12345'], # announce dns
207214
'bind-addr': ['127.0.0.1:12345', '[::1]:12345']} # and bind local IPs

0 commit comments

Comments
 (0)