-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Using VecDeque for pending events in various protocols causes task to not wake when a new event is added #5147
Comments
Didn't see any problem with current implementation. My custom behaviour works just fine this way. If you call async function you still need to return |
The problem is that when you return |
That makes sense. There could be many futures to be awaited so the problem doesn't surface. |
But still, this issue should be fixed in case it will surface in the future, right? |
You only need to implement a waking mechanism if you modify the state of a behaviour via additional APIs. |
So technically, Open to PRs that add a waker though if it fixes a bug for you. |
If youre polling the behaviours directly and there isnt anything in there trigger it to be polled again by the executor, I can see this happening, however I dont believe that is really the case here since i dont believe one should be polling a behaviour outside of |
The same could probably be done for |
I see, thanks |
Could you provide any code of your behaviour? We are more than welcome to explain from there what the issue would be or if there is a bug in libp2p that we could address it :). However, if you are calling a function to your behaviour that stores events meant for |
There's no need. I just wanted to know whether I should add a waker or not, and based on what you wrote I think I'll add a waker just to be on the safe side Regarding whether to add a waker to request-response and identify, I leave that up to you Thanks for everything 🙏 |
Summary
In various protocols (for example, identify and request-response), we store the pending events that the behaviour should return in
poll
inside aVecDeque
. When the queue is empty, we return Poll::Pending without doing anything with the given context in order to ensure the task is awaken when someone pushes an event to the queue.Expected behavior
When we call a behaviour's poll, and there are no more pending events, the calling task should be awaken when someone adds an event to the queue (example for adding an event to the queue from identify)
Actual behavior
The calling task isn't awaken in such case, and this can potentially lead to a deadlock if no one else wakes the task (I don't know the inner implementation of Swarm to know if maybe something else always keeps the task awake, but anyway this should be fixed in case no one in the swarm awakes the task)
Relevant log output
No response
Possible Solution
Instead of using VecDeque, use a queue that has an async blocking pop function that awaits until there is an item in the queue, and the pop function will register the current task to be awaken when a new item is added. For example, deadqueue
Version
0.53.2
Would you like to work on fixing this bug ?
Yes
The text was updated successfully, but these errors were encountered: