Commit 2681aed
authored
server: when no port is specified, try to find one (#1851)
Summary:
This patch teaches TensorBoard about `--port=default` (which is the new
default value for `--port`). If `--port=default` is specified,
TensorBoard will attempt to bind to port 6006, just as prior to this
patch. If this fails, TensorBoard will try to bind incrementally to
ports 6007, 6008, …, giving up after 10 attempts.
If an explicit port is specified, TensorBoard will not try to search for
other ports; it will fail (as before) if it cannot bind. This is the
only way in which `--port=default` and `--port=6006` differ.
This patch also changes the behavior of one edge case, at least on
Linux. Prior to this patch, explicit port numbers were interpreted
modulo 65536 (TCP ports are u16s), so `--port=71542` and `--port=6006`
had the same behavior. It is now an error on all platforms to specify a
port that does not fit in a u16.
Resolves #1848.
Test Plan:
$ bazel build //tensorboard
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ & sleep 2
[1] 223547
TensorBoard 1.13.0a0 at http://<hostname>:6006 (Press CTRL+C to quit)
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ & sleep 2
[2] 223591
TensorBoard 1.13.0a0 at http://<hostname>:6007 (Press CTRL+C to quit)
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ --port default & sleep 2
[3] 224292
TensorBoard 1.13.0a0 at http://<hostname>:6008 (Press CTRL+C to quit)
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ --port 6006 & sleep 2 # should fail
[4] 225773
E0214 15:35:08.939894 140033352959744 program.py:232] TensorBoard could not bind to port 6006, it was already in use
ERROR: TensorBoard could not bind to port 6006, it was already in use
[4]+ Exit 255 ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ --port 6006
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ --port 0 & sleep 2
[4] 226298
TensorBoard 1.13.0a0 at http://<hostname>:33673 (Press CTRL+C to quit)
$ for i in {6009..6015}; do ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ --port "$i" & done && sleep 2
[5] 226638
[6] 226639
[7] 226640
[8] 226641
[9] 226642
[10] 226643
[11] 226644
TensorBoard 1.13.0a0 at http://<hostname>:6011 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6013 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6015 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6012 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6014 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6009 (Press CTRL+C to quit)
TensorBoard 1.13.0a0 at http://<hostname>:6010 (Press CTRL+C to quit)
$ ./bazel-bin/tensorboard/tensorboard --logdir ./logs/ & sleep 2
[12] 227173
E0214 15:35:33.812504 140362460620544 program.py:232] TensorBoard could not bind to any port around 6006 (tried 10 times)
ERROR: TensorBoard could not bind to any port around 6006 (tried 10 times)
$ jobs -p | xargs kill
wchargin-branch: port-search1 parent 9b6e29e commit 2681aed
2 files changed
+67
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
294 | 299 | | |
295 | 300 | | |
296 | 301 | | |
297 | | - | |
298 | | - | |
| 302 | + | |
| 303 | + | |
299 | 304 | | |
300 | 305 | | |
301 | | - | |
302 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
303 | 310 | | |
304 | 311 | | |
305 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
347 | 349 | | |
348 | 350 | | |
349 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
350 | 367 | | |
351 | 368 | | |
352 | 369 | | |
353 | 370 | | |
354 | | - | |
| 371 | + | |
355 | 372 | | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
365 | 405 | | |
366 | | - | |
367 | | - | |
| 406 | + | |
| 407 | + | |
368 | 408 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
380 | 413 | | |
381 | 414 | | |
382 | 415 | | |
| |||
0 commit comments