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

Workers crash when queue is empty #2

Open
guice opened this issue Feb 1, 2014 · 4 comments
Open

Workers crash when queue is empty #2

guice opened this issue Feb 1, 2014 · 4 comments

Comments

@guice
Copy link

guice commented Feb 1, 2014

After queue is completed, workers commit suicide:

PHP Warning:  Redis::hSet() expects parameter 2 to be string, object given in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 77
PHP Stack trace:
PHP   1. {main}() /var/www/track/public/worker.php:0
PHP   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
PHP   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
PHP   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
PHP   5. Redis->hSet() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:77

Warning: Redis::hSet() expects parameter 2 to be string, object given in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 77

Call Stack:
    0.0003     223992   1. {main}() /var/www/track/public/worker.php:0
    0.0075     494360   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
   21.0271     533904   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
   21.0271     533904   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
   54.3804     534472   5. Redis->hSet() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:77

PHP Warning:  Redis::hGet() expects parameter 2 to be string, object given in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 79
PHP Stack trace:
PHP   1. {main}() /var/www/track/public/worker.php:0
PHP   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
PHP   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
PHP   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
PHP   5. Redis->hGet() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:79

Warning: Redis::hGet() expects parameter 2 to be string, object given in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 79

Call Stack:
    0.0003     223992   1. {main}() /var/www/track/public/worker.php:0
    0.0075     494360   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
   21.0271     533904   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
   21.0271     533904   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
   54.3805     534416   5. Redis->hGet() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:79

PHP Catchable fatal error:  Argument 1 passed to ThreadWorker\RemoteTask::__construct() must be an instance of ThreadWorker\Task, boolean given, called in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 82 and defined in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteTask.php on line 26
PHP Stack trace:
PHP   1. {main}() /var/www/track/public/worker.php:0
PHP   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
PHP   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
PHP   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
PHP   5. ThreadWorker\RemoteTask->__construct() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:82

Catchable fatal error: Argument 1 passed to ThreadWorker\RemoteTask::__construct() must be an instance of ThreadWorker\Task, boolean given, called in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php on line 82 and defined in /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteTask.php on line 26

Call Stack:
    0.0003     223992   1. {main}() /var/www/track/public/worker.php:0
    0.0075     494360   2. ThreadWorker\RemoteExecutor->work() /var/www/track/public/worker.php:12
   21.0271     533904   3. ThreadWorker\RemoteExecutor->startTask() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:23
   21.0271     533904   4. ThreadWorker\RedisQueue->start() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RemoteExecutor.php:34
   54.3806     534512   5. ThreadWorker\RemoteTask->__construct() /var/www/track/vendor/drealecs/thread-worker/lib/ThreadWorker/RedisQueue.php:82

Actually, can't exactly pin-point the exact instance this occurs. It used to happen all the time after the queue finished processing... but now it's not erroring. hrmm.

@drealecs
Copy link
Owner

drealecs commented Feb 1, 2014

I can't seem to replicate.
Can you provide a sample task you used and the way you run the worker(s)?

From what I see until now, the only way this can happen is if the queues used by RedisQueue internally might be tampered with external data. At some point, I had something in mind to check and move those kind of invalid values to some "bad-data-queue"; I'll try to do it now.

@guice
Copy link
Author

guice commented Feb 7, 2014

That may actually be what's happening. I'm using your library in conjuction with jimbojsb/workman, which creates manages/thread workers: https://github.com/jimbojsb/workman

I would have assumed each individual worker would grab its queue item, and leave the others alone. It seems once the queue is "done" all the individual works start crashing out, with the above error.

When I run this single-threaded, I never get the error. Only happens with the multi-threaded approach.

@drealecs
Copy link
Owner

drealecs commented Feb 8, 2014

Yes, indeed problems might occur if one would start a worker by forking it.
Workers are fully fledged PHP processes and it should only be started by running them from the command line.
I think that's what's missing from the documentation and I'll update it soon. Workers should be able to run indefinitely usually without output and should be started with vendor/bin/worker queue_name >/dev/null 2>&1 & on Linux and start vendor\bin\worker queue_name on Windows.

So you can start several workers and then just queue tasks.

@guice
Copy link
Author

guice commented Feb 10, 2014

That is what I do. I have a separate worker script, that is designed to work just as single worker, and a queue loader that works as queue loader. Obviously you can't run the queue loader as a fork, or things will be stepping on each other. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants