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

When using rr.serve and specifying ports, they are chosen at random if they are already occupied. #6222

Closed
jleibs opened this issue May 3, 2024 · 0 comments · Fixed by #6296
Assignees
Labels
🪳 bug Something isn't working 🐍 Python API Python logging API
Milestone

Comments

@jleibs
Copy link
Member

jleibs commented May 3, 2024

Describe the bug
Ports are chosen at random when they are already occupied.

To Reproduce
Script

#!/usr/bin/env python3
import rerun as rr
import time

def main() -> None:
    rr.init("rerun_example_serve")
    rr.serve(web_port=57158, ws_port=57159)

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Ctrl-C received. Exiting.")

if __name__ == "__main__":
    main()

Run the program twice from two separate terminals

Run1

➜  python spawn_ports.py 
[2024-05-03T22:30:55Z INFO  re_ws_comms::server] Hosting a WebSocket server on ws://localhost:57159. You can connect to this with a native viewer (`rerun ws://localhost:57159`) or the web viewer (with `?url=ws://localhost:57159`).
[2024-05-03T22:30:55Z INFO  re_web_viewer_server] Started web server on http://localhost:57158
[2024-05-03T22:30:55Z INFO  re_sdk::web_viewer] Hosting a web-viewer at http://localhost:57158?url=ws://localhost:57159
^CCtrl-C received. Exiting.
[2024-05-03T22:31:03Z INFO  re_ws_comms::server] Shutting down Rerun server on ws://localhost:57159
[2024-05-03T22:31:03Z INFO  re_web_viewer_server] Shutting down web server on http://localhost:57158

Run 2

➜  python spawn_ports.py 
[2024-05-03T22:31:00Z INFO  re_ws_comms::server] Hosting a WebSocket server on ws://localhost:42271. You can connect to this with a native viewer (`rerun ws://localhost:42271`) or the web viewer (with `?url=ws://localhost:42271`).
[2024-05-03T22:31:00Z INFO  re_web_viewer_server] Started web server on http://localhost:33623
[2024-05-03T22:31:00Z INFO  re_sdk::web_viewer] Hosting a web-viewer at http://localhost:33623?url=ws://localhost:42271
^CCtrl-C received. Exiting.
[2024-05-03T22:31:03Z INFO  re_ws_comms::server] Shutting down Rerun server on ws://localhost:42271
[2024-05-03T22:31:03Z INFO  re_web_viewer_server] Shutting down web server on http://localhost:33623

Expected behavior
The second run should fail with a warning about the ports being occupied.

Desktop (please complete the following information):

  • OS: Linux

Rerun version
0.15.1

@jleibs jleibs added 🪳 bug Something isn't working 🐍 Python API Python logging API 👀 needs triage This issue needs to be triaged by the Rerun team labels May 3, 2024
@jleibs jleibs added this to the 0.16 milestone May 3, 2024
@jleibs jleibs removed the 👀 needs triage This issue needs to be triaged by the Rerun team label May 3, 2024
Wumpf added a commit that referenced this issue May 13, 2024
… already in use, only recommend using 0 instead (#6296)

### What

* Fixes #6222

Running this scrip twice:
```py
#!/usr/bin/env python3
import rerun as rr
import time

def main() -> None:
    rr.init("rerun_example_serve")
    rr.serve(web_port=57158, ws_port=57159)

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Ctrl-C received. Exiting.")

if __name__ == "__main__":
    main()
```

Gives now this error:

```sh
Traceback (most recent call last):
  File "/Users/andreas/dev/rerun-io/rerun/test.py", line 18, in <module>
    main()
  File "/Users/andreas/dev/rerun-io/rerun/test.py", line 8, in main
    rr.serve(web_port=57158, ws_port=57159)
  File "/Users/andreas/dev/rerun-io/rerun/rerun_py/rerun_sdk/rerun/sinks.py", line 252, in serve
    bindings.serve(
RuntimeError: Failed to bind to WebSocket port 57159 since the address is already in use. Use port 0 to let the OS choose a free port.
```

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6296?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6296?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6296)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪳 bug Something isn't working 🐍 Python API Python logging API
Projects
None yet
2 participants