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

Support multiple source/dest addresses #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

DJAndries
Copy link
Collaborator

No description provided.

@DJAndries DJAndries requested a review from rillian July 20, 2024 04:30
src/main.rs Outdated
})
})
.collect::<JoinSet<_>>();
join_set.join_next().await.unwrap().unwrap().unwrap()

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] expect or unwrap called in function returning a Result

Source: https://semgrep.dev/r/trailofbits.rs.panic-in-function-returning-result.panic-in-function-returning-result


Cc @thypon @bcaller

Copy link
Contributor

@rillian rillian Jul 22, 2024

Choose a reason for hiding this comment

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

I kinda agree with semgrep here. The current code doesn't actually exit through this path, but the unwraps are hard to follow. It also seems odd to exit after the first task without waiting for the others to complete (future, hypothetical) cleanup. What about something like

// Wait until all listening tasks exit...
while let Some(task) = join_set.join_next().await {
    let _ = task.context("Listener task error")?;
    info!("Listener task completed ok");
}
Ok(())

Copy link
Collaborator Author

@DJAndries DJAndries Aug 2, 2024

Choose a reason for hiding this comment

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

The current code doesn't actually exit through this path, but the unwraps are hard to follow

Replaced the unwraps with expects to add more context on the errors that are being managed. They are placed there to handle a condition that wouldn't happen at all (the JoinSet being empty), or panics within the forwarding tasks themselves. The actual anyhow Result is still returned to the main function.

What about something like

A 'successful' task will never actually complete, it will continue to forward requests indefinitely. I added a subsequent 'shutdown' call to abort all other tasks when an error is encountered.

@DJAndries DJAndries requested a review from claucece August 26, 2024 20:13
Copy link
Member

@claucece claucece left a comment

Choose a reason for hiding this comment

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

LGTM!

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

Successfully merging this pull request may close these issues.

5 participants