-
Notifications
You must be signed in to change notification settings - Fork 29
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
Issue #182 Fixes a problematic loop in produce_simulation_results #183
Conversation
sim-lib/src/sim_node.rs
Outdated
@@ -1521,7 +1521,7 @@ mod tests { | |||
/// Alice (100) --- (0) Bob (100) --- (0) Carol (100) --- (0) Dave | |||
/// | |||
/// The nodes pubkeys in this chain of channels are provided in-order for easy access. | |||
async fn new(capacity: u64) -> DispatchPaymentTestKit<'a> { | |||
async fn new(capacity: u64) -> Self { |
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.
let's squash this commit 👍
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.
Thanks for the fix (and detection!!), only one real comment here.
Going to tag a patch once this goes in so that we can get a fresh docker image out.
while let Some(res) = tasks.join_next().await { | ||
if let Err(e) = res { | ||
log::error!("Task exited with error: {e}."); | ||
} | ||
} |
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.
Let's pull this out into a closure to de-dup it a little?
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.
Any suggestions on what that closure should look like? It will have to be async
which is always tricky to me.
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.
Async closures are dark magic indeed :') Since we're also using it in produce_simulation_results
it can probably just be a utility function instead.
Closure could have been something like this:
let wait_for_tasks = |mut tasks: JoinSet<()>| async move {
while let Some(res) = tasks.join_next().await {
if let Err(e) = res {
log::error!("Task exited with error: {e}.");
}
}
};
sim-lib/src/lib.rs
Outdated
@@ -1158,7 +1188,7 @@ async fn produce_simulation_results( | |||
tokio::select! { | |||
biased; | |||
_ = listener.clone() => { | |||
return Ok(()) | |||
break; |
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.
TIL that you can return a value with break
in rust - perhaps we can do this here?
let result = loop ....
and then break Ok(())
/ break Err(())
and then go on to the joinset wait at the end. Has the advantage of always waiting for everything to close out cleanly vs current approach where we only wait on Ok()
exits.
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.
Yes, that is a great idea! Just added that in the latest commit.
31600b6
to
4b6873f
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.
tACK, last comment non-blocking (only saves us a few lines).
Resolves Issue #182 by removing
set.join_next()
from thetokio::select!
statement and waiting for tasks to finish outside of the loop. Also does some error handling in therun
function in case we encounter an error after starting data collection threads.