Skip to content

Commit 4976e91

Browse files
committed
test: fix IPv6 support detection
`test_ipv6_local()` could have returned false whereas subsequently bitcoind successfully binds to `::`. This is because the previously used `s.connect(('::1', 0))` can throw an exception like `[Errno 99] Cannot assign requested address` on hosts where IPv6 is available and bitcoind readily binds to `::`.
1 parent d67883d commit 4976e91

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/functional/test_framework/netutil.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ def test_ipv6_local():
146146
Check for (local) IPv6 support.
147147
'''
148148
import socket
149-
# By using SOCK_DGRAM this will not actually make a connection, but it will
150-
# fail if there is no route to IPv6 localhost.
151-
have_ipv6 = True
152-
try:
153-
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
154-
s.connect(('::1', 0))
155-
except socket.error:
156-
have_ipv6 = False
157-
return have_ipv6
149+
if socket.has_ipv6:
150+
s = None
151+
try:
152+
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
153+
s.bind(('::', 0))
154+
return True
155+
except OSError:
156+
pass
157+
finally:
158+
if s:
159+
s.close()
160+
return False

0 commit comments

Comments
 (0)