-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conflict between await and execute command #14
Comments
Ok, this got sent accidentally too early, I'll fix the formatting now.. (Fixed). |
I don't attach a Pull Request - your code is beautiful and surely you can write a better solution based on the idea. Thank you for a package! |
Hi, thank you for the thorough examination of the problem. Both I think what the fix should do is to create "scopes" of |
… after socket polling.
… after socket polling.
… after socket polling.
Hello, thx for the great project. |
First of all - thanks for the wonderful package!
Second, i think there is a flaw in how the messages are handled if you use callbacks and call another method from within a callback.. The bug is tricky, because it depends on the ordering of the messages between client and server, so it takes a few runs to catch it.
Relevant parts:
What I expect this program to do:
to finish without timeout
What happens:
in some percentage of cases (50%?) it ends with a timeout on
awaitLoadEventFired
The full source is here https://gist.github.com/slava-vishnyakov/057d2dfb0b9b1bad878130c9607e3179
Ok, so now we have something like this:
awaitLoadEventFired
loopshandleMessage
waiting forPage.loadEventFired
Network.loadingFinished
messages, which trigger a callback, which then calls forgetResponseBody
methodPage.loadEventFired
happens to be in thisgetReponseBody
loop, not inawaitLoadEventFired
and thereforeawaitLoadEventFired
never sees thisPage.loadEventFired
event.I've added a few debug prints to see this:
So as I understand it, it goes like this:
So, the fix should be something like "if we are
await
ing for something and deep handleMessage gets it - we need to "bubble" it somehow"..The problem gets deeper, since a callback might call
executeCommand
, which will trigger a callback, which will trigger another callback, which might call anotherexecuteCommand
..So, basically we can't have something like a
$this->await[$method] = {null | XX_Response}
, we need something more clever, which will say thatwe have 2 awaits upstream waiting for XX
So, my first stab at the fix (quite a bit ugly, but I don't know how to express it better):
(noticed that in this version I have
$this->awaits
-- it should be$this->awaitMethods
, this is corrected in code below)Basically we have two new instance variables - the number of awaits upstream waiting for particular method (
$awaitMethods
(naming is hard...$methodAwaitersCount
? :) )) and responses for those ($awaitMessages
).Now, when we enter
handleMessage
- we look whether there is an await upstream for this method. If there is - we don't process it and store to$awaitMessages
variable..After we return from callback - we look if there is a message for this method stored for us. If there is - we decrement the number of "awaiters" and return the message..
The new handleMessage:
The text was updated successfully, but these errors were encountered: