-
Notifications
You must be signed in to change notification settings - Fork 108
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
Shut down channels and tasks on PeerSet Drop #3078
Conversation
@jvff asked:
How did you want to handle the background tasks separately? The listener, crawler, and address book updater background tasks are required for the I'm also not sure if we need to do anything else to shutdown. On startup,
Once the last peer set clone is dropped, all the So I'm not sure if separate shutdown channel is needed? When we do full graceful shutdown in #1678, we can add channels as needed. |
I'm not exactly sure, but I guess the core of what I'm worried about is that
I think the Regarding handling background/startup tasks, I think the goals are:
In order to achieve those goals, when focusing on the
I'm not sure how to handle this in this PR. It might make sense to not change the PR right now and think more about this in a broader " One idea for the latter might be to create
And such types would have a Anyway, I'm not sure if I'm helping or just brain dumping a wild idea 😓 |
zebra-network/src/peer_set/set.rs
Outdated
self.shut_down_tasks_and_channels(); | ||
|
||
exit_error |
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.
Optional idea: I'm worried that this poll_background_errors
might become hard to read, because a quick glance seems like the function polls and shuts down the tasks and channels. I'd suggest refactoring this so that the normal flow is more evident. Maybe splitting this method in more methods should help:
fn poll_background_errors(&mut self, cx: &mut Context) -> Result<(), BoxError> {
self.receive_guards_if_needed();
match Pin:::new(&mut self.guards).poll_next(cx) {
Poll::Pending => Ok(()),
Poll::Ready(maybe_task_result) => self.shutdown_with_result(
maybe_task_result.unwrap_or_else(|| {
Err("all peer set background tasks have exited".into())
}),
),
}
}
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.
Fixed in e15e1b1, along with checking the channel during shutdown.
64c904b
to
e15e1b1
Compare
Just a reminder that the goal of this PR is:
Anything else is out of scope for the NU5 mainnet activation sprints. Unless it's important for doing #2262.
The inbound service uses the address book, so we would either need to:
Feel free to open a ticket for this change if you'd like, and we can schedule it in a future sprint.
We do this already:
There might be bugs or missing parts of this implementation, but they're covered by ticket #1678.
I'd like to leave this PR where it is, unless there is an obvious major bug that blocks #2262.
Can you open a ticket for this change, and we can schedule it in a future sprint? |
Also, split receiving and polling background tasks into separate methods.
55d8423
to
7760bf1
Compare
Bumping this to medium priority, because it's blocking #2262. |
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.
Everything looks good. I just added two small optional suggestions.
/// Stores gossiped inventory from connected peers. | ||
/// Used to route inventory requests to peers that are likely to have it. |
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.
Nit: Not sure if this was on purpose, but maybe separate the second sentence into the details section?
/// Stores gossiped inventory from connected peers. | |
/// Used to route inventory requests to peers that are likely to have it. | |
/// Stores gossiped inventory from connected peers. | |
/// Used to route inventory requests to peers that are likely to have it. |
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.
for handle in handles { | ||
self.guards.push(handle); | ||
} |
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.
Optional suggestion to make it shorter:
for handle in handles { | |
self.guards.push(handle); | |
} | |
self.guards.extend(handles); |
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.
Motivation
We want to shut down the peer set properly. We also want to detect peer and background task errors during shutdown.
This is a partial fix for #1678 and #1351, before we modify the peer set in #2262.
Solution
Review
This is a fix from @jvff's review #3072 (comment)
But the changes were originally part of PR #3071.
Reviewer Checklist
Follow Up Work
Keep implementing shut down for the rest of Zebra
Give the peer set an explicit shutdown handle?