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

chore(rust)::> used portpicker crate to avoid port clash in ockam examples #8304

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

PsychoPunkSage
Copy link
Contributor

Current behavior

Some tests in examples/rust/* could clash on TCP ports when run in parallel.

Proposed changes

Use portpicker crate to avoid port clash. Now tests will ask the OS for free ports, rather then using hardcoded values.

This PR addresses #3005 pointer 2

@PsychoPunkSage PsychoPunkSage requested a review from a team as a code owner July 12, 2024 12:57
@PsychoPunkSage PsychoPunkSage changed the title fix::> used portpicker crate to avoid port clash chore::> used portpicker crate to avoid port clash Jul 12, 2024
@PsychoPunkSage PsychoPunkSage changed the title chore::> used portpicker crate to avoid port clash refactor(rust)::> used portpicker crate to avoid port clash Jul 15, 2024
Copy link
Member

@metaclips metaclips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the commit message to chore(rust): used portpicker crate to avoid port clash in ockam examples

examples/rust/tcp_inlet_and_outlet/Cargo.toml Outdated Show resolved Hide resolved
@PsychoPunkSage PsychoPunkSage changed the title refactor(rust)::> used portpicker crate to avoid port clash chore(rust)::> used portpicker crate to avoid port clash Jul 15, 2024
@PsychoPunkSage PsychoPunkSage changed the title chore(rust)::> used portpicker crate to avoid port clash chore(rust)::> used portpicker crate to avoid port clash in ockam examples Jul 15, 2024
@PsychoPunkSage
Copy link
Contributor Author

Hi @metaclips
I have replaced portpicker crate with the solution pointed by @adrianbenavides
I have on thing to report...
run_04_inlet_outlet_seperate_processes_secure_channel_via_ockam_hub is failing... due to some reasons... (not because of newly implemented portfinder.rs, i have verified that)

@PsychoPunkSage
Copy link
Contributor Author

Hi @adrianbenavides
Did the requested changes.
Please have a look at it.

@PsychoPunkSage
Copy link
Contributor Author

Hi @adrianbenavides
Did the changes... but should we keep the custom error variants BindError and AddrError but modify them to include io::Error??
like this

pub enum Error {
......
    #[error("failed to bind with given address")]
    BindError(#[source] io::Error),
    #[error("failed to get local socket address of the listener")]
    AddrError(#[source] io::Error),
}

pub fn find_available_port() -> Result<u16> {
    let listener = TcpListener::bind("127.0.0.1:0").map_err(Error::BindError)?;
    let address = listener.local_addr().map_err(Error::AddrError)?;
    Ok(address.port())
}

@adrianbenavides
Copy link
Member

Hi @adrianbenavides Did the changes... but should we keep the custom error variants BindError and AddrError but modify them to include io::Error?? like this

pub enum Error {
......
    #[error("failed to bind with given address")]
    BindError(#[source] io::Error),
    #[error("failed to get local socket address of the listener")]
    AddrError(#[source] io::Error),
}

pub fn find_available_port() -> Result<u16> {
    let listener = TcpListener::bind("127.0.0.1:0").map_err(Error::BindError)?;
    let address = listener.local_addr().map_err(Error::AddrError)?;
    Ok(address.port())
}

It's not necessary in this case. Generally, you don't want to map every possible error into an enum variant, just the ones you want to act upon. In this case, we just want to convert external error types into our own and print them.

@adrianbenavides
Copy link
Member

Thanks @PsychoPunkSage for this PR 🙏 It looks good, but you'll also have to sign your commits here before I can approve it.

https://docs.github.com/en/authentication/managing-commit-signature-verification

@PsychoPunkSage
Copy link
Contributor Author

Hi @adrianbenavides
Added Signed commits that you requested

Copy link
Member

@adrianbenavides adrianbenavides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge, thanks a lot @PsychoPunkSage for your PR!! 🙏

@adrianbenavides adrianbenavides added this pull request to the merge queue Aug 1, 2024
Merged via the queue into build-trust:develop with commit 5cbacda Aug 1, 2024
27 checks passed
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

Successfully merging this pull request may close these issues.

4 participants