Skip to content

Commit de3078c

Browse files
authored
Don't automatically fall back to automatic port if web socket port is 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`.
1 parent 3a42904 commit de3078c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

crates/re_ws_comms/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub enum RerunServerError {
3434
#[error("Failed to bind to WebSocket port {0}: {1}")]
3535
BindFailed(RerunServerPort, std::io::Error),
3636

37+
#[error("Failed to bind to WebSocket port {0} since the address is already in use. Use port 0 to let the OS choose a free port.")]
38+
BindFailedAddrInUse(RerunServerPort),
39+
3740
#[error("Received an invalid message")]
3841
InvalidMessagePrefix,
3942

crates/re_ws_comms/src/server.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,13 @@ impl RerunServer {
104104
) -> Result<Self, RerunServerError> {
105105
let bind_addr = format!("{bind_ip}:{port}");
106106

107-
let listener_socket = match TcpListener::bind(bind_addr) {
108-
Ok(listener) => listener,
109-
Err(err) if err.kind() == std::io::ErrorKind::AddrInUse => {
110-
let bind_addr = format!("{bind_ip}:0");
111-
112-
TcpListener::bind(bind_addr)
113-
.map_err(|err| RerunServerError::BindFailed(RerunServerPort(0), err))?
107+
let listener_socket = TcpListener::bind(bind_addr).map_err(|err| {
108+
if err.kind() == std::io::ErrorKind::AddrInUse {
109+
RerunServerError::BindFailedAddrInUse(port)
110+
} else {
111+
RerunServerError::BindFailed(port, err)
114112
}
115-
Err(err) => return Err(RerunServerError::BindFailed(port, err)),
116-
};
113+
})?;
117114

118115
// Blocking listener socket seems much easier at first glance:
119116
// No polling needed and as such no extra libraries!

0 commit comments

Comments
 (0)