Skip to content

Commit ee6c660

Browse files
schnell18Justin Zhangblink1073
authored
Support IPV6 in _find_http_port() (#1207)
Co-authored-by: Justin Zhang <[email protected]> Co-authored-by: Steven Silvester <[email protected]>
1 parent 0111798 commit ee6c660

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

jupyter_server/serverapp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,9 +2403,14 @@ def _bind_http_server_tcp(self):
24032403

24042404
def _find_http_port(self):
24052405
"""Find an available http port."""
2406+
pat = re.compile("([a-f0-9:]+:+)+[a-f0-9]*")
24062407
success = None
24072408
for port in random_ports(self.port, self.port_retries + 1):
2408-
tmp_sock = socket.socket()
2409+
tmp_sock = (
2410+
socket.socket()
2411+
if pat.match(self.ip) is None
2412+
else socket.socket(family=socket.AF_INET6)
2413+
)
24092414
try:
24102415
tmp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, b"\0" * 8)
24112416
tmp_sock.bind((self.ip, port))

0 commit comments

Comments
 (0)