Closed mmenozzi closed 5 years ago
No, the check just hides the error. We have to find the cause.
My initial guess would be that it might happen on connection closes?
I don't think so. I did some other investigation and what can I say is that it happens during the execution of this method (but only sometimes, I think it depends on what is in the tube):
Do you see any unexpected usage in this method?
Closing after #26 is fixed, that's probably the cause.
Example
10\r\n
..........\r\n
If the following is in the buffer
10\r\n
..........
Then the if
with the return
is skipped: 4 + 2 + 14 < 10 + 4
Hi, I use the AMP's beanstalk client with https://github.com/webgriffe/esb. Sometimes (but I never found the cause) the ESB application crashes with the following error:
That
resolve
is the one inside theresponse
event callback of the client:And this is strange because only
Deferred
instances are added to theBeanstalkClient::$deferreds
array.https://github.com/amphp/beanstalk/blob/9973d81a1a292ec09d8ab5ffd08e61dc435c664a/src/BeanstalkClient.php#L55 https://github.com/amphp/beanstalk/blob/9973d81a1a292ec09d8ab5ffd08e61dc435c664a/src/BeanstalkClient.php#L68
So it seems that, sometimes, the
response
event is fired when theBeanstalkClient::$deferreds
array is empty. Indeed,array_shift
returnsnull
if the array is empty (http://php.net/manual/en/function.array-shift.php).I don't know how this could happen but happens...
Maybe we can prevent such error with a simple check:
But I don't know if the right thing to do. @kelunik what do you think?