-
Notifications
You must be signed in to change notification settings - Fork 959
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
Handeling of events received in kad::Handler could be delayed or blocked #4960
Comments
Thank you for your debugging work and the elaborate explanation. I am still confused by one thing. Sorry in case I am missing something. It is rather late in my day. Once the connection task called rust-libp2p/swarm/src/connection/pool/task.rs Lines 178 to 186 in 9584ee3
Shouldn't this make the fix in #4961 obsolete? |
Yes indeed. I had not succeeded in finding where the As for #4961 not being necessary, indeed, since there does not seem to be a case where the bug could happen, it might not be required to do it. However, we should be careful in the future because, since the contract of the I'll let you decide what you prefer, and I will understand either way 😊 |
I'll close this as not necessary. If you want, we can merge a documentation update that explains this @stormshield-frb ! Thank you for the work! :) |
Summary
When trying to understand the cause of #4948, we detected a potential bug in the implementation of
Handler::poll
: events received inon_behaviour_event
, could be handled very late or maybe never.The
outbound_substreams
field is aFuturesMap
. When callingpoll_unpin
on aFuturesMap
, if there are no more futures to be run (i.e., if theFuturesMap
is empty), it returnsPoll::Pending
and registers a waker (self.empty_waker
) which will be triggered on the nexttry_push
call (i.e., when a new future has to be run).However, when reading how
poll_unpin
is called foroutbound_substreams
(inHandler::poll
), we can identify a "snake biting its tail" behaviour :In the
Handler::poll
implementation, there is only two calls that can register a waker when returningPoll::Pending
:self.outbound_substreams.poll_unpin(cx)
self.inbound_substreams.poll_next_unpin(cx)
As we have seen,
self.outbound_substreams.poll_unpin(cx)
registers awaker
on the next call totry_push
. Unfortunately, the call totry_push
depends on the call toself.queue_new_stream
which is itself uniquely present in theHandler::poll
method. That means that, if there are no more futures inoutbound_substream
and thatpending_messages
is also empty, the only thing waking thepoll
method back on isself.inbound_substreams.poll_next_unpin(cx)
(i.e., when pushing topending_messages
there could be an important delay before messages are handled).Expected behavior
Pushing to
self.pending_messages
should allow messages to be handled as soon as possible.Actual behavior
Pushing to
self.pending_messages
do not really wake upoutbound_substreams
.Relevant log output
No response
Possible Solution
I'm going to do a PR and tag this issue.
Version
Current master branch.
Would you like to work on fixing this bug ?
Yes
The text was updated successfully, but these errors were encountered: