Skip to content
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

Reserving a job from an empty queue throws an "Unknown Error" #14

Open
advitum opened this issue Jul 19, 2019 · 15 comments
Open

Reserving a job from an empty queue throws an "Unknown Error" #14

advitum opened this issue Jul 19, 2019 · 15 comments
Labels
question Further information is requested

Comments

@advitum
Copy link

advitum commented Jul 19, 2019

This is a bug report.

When reserving a job using $client->reserve();, an unknown error gets thrown when the queue is empty.

According to the documentation (and the source code), an empty queue should not throw an error, but instead result in a Job with id=null.

$client = new BeansClient(new Connection());
$client->watchTube('Project.Orders');
$job = $client->reserve(30);

// Exception: Unknown error in [/xobotyi/beansclient/src/Socket/SocketBase.php, line 158]
Stack Trace:
#0 /vendor/xobotyi/beansclient/src/Socket/SocketBase.php(175): xobotyi\beansclient\Socket\SocketBase->throwLastError()
#1 /vendor/xobotyi/beansclient/src/Connection.php(120): xobotyi\beansclient\Socket\SocketBase->readLine()
#2 /vendor/xobotyi/beansclient/src/BeansClient.php(76): xobotyi\beansclient\Connection->readLine()
#3 /vendor/xobotyi/beansclient/src/BeansClient.php(317): xobotyi\beansclient\BeansClient->dispatchCommand(Object(xobotyi\beansclient\Command\Reserve))
#4 /src/Command/OrdersCommand.php(30): xobotyi\beansclient\BeansClient->reserve(30)
[...]

Versions i'm using:

  • OS: OSX
  • PHP: 7.3.3
  • BeansClient: v1.0.1
  • beanstalkd: 1.11
@xobotyi
Copy link
Owner

xobotyi commented Jul 23, 2019

Try an alpha version, this problem should be solved there.

@splastunov
Copy link

Hello!

I've got the same error on alpha...

@xobotyi
Copy link
Owner

xobotyi commented Sep 4, 2019

@splastunov what is your use case?

@splastunov
Copy link

$beansConnection = new xobotyi\beansclient\Connection('127.0.0.1', 11300, 2, true);
$beansClient = new xobotyi\beansclient\BeansClient($beansConnection);

//Watch tube and get task
$job = $beansClient->watchTube('myTube')->reserve();

Failed with the same Socket error if Tube is empty.

Even if you would try to watch empty Tube with watchTube it will fail.

Allsow you have errors at documentation.
listTubeUsed should be listUsedTubes
and etc...

@xobotyi
Copy link
Owner

xobotyi commented Sep 4, 2019

Due to it is alpha it's not documented yet.

@Punkley
Copy link

Punkley commented Oct 25, 2019

Also seeing this issue, from what I can tell, the readline isn't waiting or is failing because its not returning anything straight away.

It happens when you do a reserve-with-timeout

@Punkley
Copy link

Punkley commented Oct 25, 2019

OK I have worked out what the bug is

$result = fgets($this->socket, 8192);
in Function ReadLine means the wait for the fgets is very short eg 1 sec.

If you are using reserve-with-timeout say set to 60, you need readline to wait for at least 60 seconds

eg with something like
stream_set_timeout($this->socket, 65);

@xobotyi
Copy link
Owner

xobotyi commented Oct 27, 2019

@Punkley have you checked that? If that solves the issue ill dig into it in that direction

@Punkley
Copy link

Punkley commented Oct 27, 2019 via email

@xobotyi
Copy link
Owner

xobotyi commented Oct 28, 2019

@Punkley check out the master branch. Pushed the fix, not tested yet, but it should help.

@Punkley
Copy link

Punkley commented Oct 31, 2019

so far, so good :)

@Punkley
Copy link

Punkley commented Nov 14, 2019

OK I think a slight tweak is needed,

Every now and then about every 10th time I get
PHP Fatal error: Uncaught xobotyi\beansclient\Exception\SocketException: Unknown error in vendor/xobotyi/beansclient/src/Socket/SocketBase.php:185

I think I have however solved the issue by adding this
$timeout !== null && stream_set_timeout($this->socket, $timeout +5);

eg the timeout needs to be just a little longer then the actual beanstalk timeout.

@Punkley
Copy link

Punkley commented Nov 15, 2019

after making that change, the script has been running for 12 hours+

Kingsley

@xobotyi
Copy link
Owner

xobotyi commented Jan 28, 2020

@Punkley 5 seconds is pretty much, have you tried smaller values?

xobotyi added a commit that referenced this issue Jan 30, 2020
* Added read timeout for command that has it, possible fix of #14

* Added read timeout leeway.
@xobotyi
Copy link
Owner

xobotyi commented Feb 3, 2020

@Punkley hello again.
Ive attempted to improve the sockets interconnection, check out the v2.0.0-alpha.13 please.

@xobotyi xobotyi added the question Further information is requested label Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants