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

Bug Fix: Update the port scanning logic to properly skip ports in use #6560

Merged
merged 2 commits into from
Aug 29, 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
12 changes: 11 additions & 1 deletion tensorboard/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def configure(self, argv=("",), **kwargs):
# any positional arguments to `serve`.
serve_parser = serve_subparser

for (name, subcommand) in self.subcommands.items():
for name, subcommand in self.subcommands.items():
subparser = subparsers.add_parser(
name,
help=subcommand.help(),
Expand Down Expand Up @@ -698,7 +698,17 @@ def __init__(self, wsgi_app, flags):
self._url = None # Will be set by get_url() below

self._fix_werkzeug_logging()

def is_port_in_use(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) == 0

try:
if is_port_in_use(port):
raise TensorBoardPortInUseError(
"TensorBoard could not bind to port %d, it was already in use"
% port
)
super().__init__(host, port, wsgi_app, _WSGIRequestHandler)
except socket.error as e:
if hasattr(errno, "EACCES") and e.errno == errno.EACCES:
Expand Down