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

Floresta-cli error: Address already in use #282

Open
JoseSK999 opened this issue Nov 19, 2024 · 2 comments
Open

Floresta-cli error: Address already in use #282

JoseSK999 opened this issue Nov 19, 2024 · 2 comments

Comments

@JoseSK999
Copy link
Contributor

JoseSK999 commented Nov 19, 2024

We hadn't seen this error for a while but it has just popped up in our CI. I don't think it's related to the new cross-feature testing.

thread 'main' panicked at florestad/src/json_rpc/server.rs:672:17:
Could not start HTTP JSON-RPC server at 127.0.0.1:38969: Address already in use (os error 98)

Error explanation

In floresta-cli tests, we temporarily bind to an available port, release it, and pass it to florestad. This way we know on the client side which port to use for the JSON-RPC client:

let port = get_available_port();
let fld = Command::new(&florestad_path)
    // ...
    // Pass the port to florestad
    .args(["--rpc-address", &format!("127.0.0.1:{}", port)])
    // ...

// Use the fetched port for client
let client = Client::new(format!("http://127.0.0.1:{port}"));

To ensure the port is released by the OS before florestad re-binds to it, I added a 100ms delay in get_available_port.

This has worked so far, but it's not robust: there's a brief window between floresta-cli's initial binding and florestad's re-binding where another process could claim the port.

I think the best solution is for florestad to bind directly to an available port and output this port via stdout, allowing floresta-cli to know which port to use as a client.

@Davidson-Souza
Copy link
Collaborator

I think the best solution is for florestad to bind directly to an available port and output this port via stdout, allowing floresta-cli to know which port to use as a client.

Sounds like something doable, you just have to change the logic of how we log the port used and find this on stdout before using floresta-cli right? Sounds like the only annoying part would be to find the port and use it in the rest of the script.

@JoseSK999
Copy link
Contributor Author

During start_florestad we read the port from stdout yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants