-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Conversation
src/main.rs
Outdated
}) | ||
}) | ||
.collect::<JoinSet<_>>(); | ||
join_set.join_next().await.unwrap().unwrap().unwrap() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(())
There was a problem hiding this comment.
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 unwrap
s with expect
s 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.
9b1665a
to
82f8b25
Compare
82f8b25
to
a4c3665
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.