-
Notifications
You must be signed in to change notification settings - Fork 694
p2p: A couple fixes to KademliaProtocol/PeerPool #767
Conversation
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.
just the Lock
request
p2p/peer.py
Outdated
if self._discovery_lookup_running: | ||
self.logger.debug("Node discovery lookup already in progress, not running another") | ||
return | ||
self._discovery_lookup_running = True |
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.
Can we use an asyncio.Lock
for this instead of a true/false? They support use as a context manager which allows for a cleaner API here.
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.
Definitely! Should've thought of that myself
p2p/peer.py
Outdated
async def maybe_lookup_random_node(self) -> None: | ||
if self._discovery_last_lookup + self._discovery_lookup_interval > time.time(): | ||
return | ||
if self._discovery_lookup_running: |
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.
nitpick
Can you make this an elif
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.
Sure thing
de5ee62
to
e34496c
Compare
p2p/peer.py
Outdated
elif self._discovery_lookup_running.locked(): | ||
self.logger.debug("Node discovery lookup already in progress, not running another") | ||
return | ||
with (await self._discovery_lookup_running): |
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.
is this equvalent to async with self.discovery_lookup_running
?
That's what I found here: https://www.pythonsheets.com/notes/python-asyncio.html
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.
Looks like it: https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with
I'll switch to async with
; I think that reads better
- Ensure PeerPool never runs multiple node discovery lookups in parallel - KademliaProtocol.bond() no longer triggers self.populate_not_full_buckets() when bondig fails as that can potentially create a never-ending bonding spiral
e34496c
to
2d60366
Compare
self.populate_not_full_buckets() when bondig fails as that can
potentially create a never-ending bonding spiral
The
AlreadyWaiting
errors (#737) seem to be gone with these changes