-
Notifications
You must be signed in to change notification settings - Fork 120
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
Refactor and document correctness for std::sync::Mutex<AddressBook> #2033
Refactor and document correctness for std::sync::Mutex<AddressBook> #2033
Conversation
Hey @oxarbitrage can you review this PR soon? It's blocking #2035. |
let peers = address_book.lock().unwrap().clone(); | ||
let mut peers = peers.sanitized(); |
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.
@fanatid our external address should be added to the cloned peers before they are sanitized()
.
// TODO: reduce mutex contention by moving the filtering into | ||
// the address book itself | ||
// the address book itself (#1976) |
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.
👍
// In this critical section, we hold the address mutex, blocking the | ||
// current thread, and all async tasks scheduled on that thread. |
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.
⚠👍
// TODO: replace with a watch channel that is updated in `AddressBook::update_metrics()`, | ||
// or turn the address book into a service (#1976) |
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
The shared peer address book uses a threaded mutex. So when we're waiting for the lock in async code, we need to be careful to avoid blocking all the tasks on that thread for too long.
Solution
The code in this pull request has:
Review
@oxarbitrage can review once I've tested it locally.
Related Issues
Implements part of #1995
Follow Up Work
The address book and candidate set code is really complex. It would be easier to avoid hang bugs if they were rewritten as services (#1976).