Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IPV6 in _find_http_port() #1207

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2403,9 +2403,14 @@ def _bind_http_server_tcp(self):

def _find_http_port(self):
"""Find an available http port."""
pat = re.compile("([a-f0-9:]+:+)+[a-f0-9]*")
success = None
for port in random_ports(self.port, self.port_retries + 1):
tmp_sock = socket.socket()
tmp_sock = (
socket.socket()
if pat.match(self.ip) is None
else socket.socket(family=socket.AF_INET6)
)
try:
tmp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, b"\0" * 8)
tmp_sock.bind((self.ip, port))
Expand Down