Skip to content

Support multiple source/dest addresses - #32

Open
DJAndries wants to merge 2 commits into
masterfrom
multi-forward
Open

Support multiple source/dest addresses#32
DJAndries wants to merge 2 commits into
masterfrom
multi-forward

Conversation

@DJAndries

Copy link
Copy Markdown
Collaborator

No description provided.

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

Copy link
Copy Markdown

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

@rillian rillian Jul 22, 2024

Copy link
Copy Markdown
Contributor

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(())

@DJAndries DJAndries Aug 2, 2024

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/main.rs
Comment thread src/main.rs
Comment thread src/main.rs
Comment thread src/main.rs
Comment thread src/main.rs
@DJAndries
DJAndries requested a review from claucece August 26, 2024 20:13

@claucece claucece left a comment

Copy link
Copy Markdown
Member

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