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

PHP GearmanClient::doBackground just hangs #241

Closed
kvelaro opened this issue May 16, 2019 · 7 comments
Closed

PHP GearmanClient::doBackground just hangs #241

kvelaro opened this issue May 16, 2019 · 7 comments

Comments

@kvelaro
Copy link

kvelaro commented May 16, 2019

It's just does not work under PHP5.4 (centos 6). Tried to look at source, without success. https://stackoverflow.com/questions/56152265/php-gearmanclientdobackground-just-hangs. Could you please advice something? Killed almost week

@esabol
Copy link
Member

esabol commented May 16, 2019

Are you starting gearmand with --verbose DEBUG arguments? If not, please do so. Then reproduce and check the gearmand.log for more information and post the relevant log section here.

Also, maybe try to reproduce the issue without using PHP. The issue might not be with gearmand.

Are you sure your workers always send WORK_COMPLETE? See issue #161.

Are you doing anything with signals or alarms in PHP? If so, see issue #230.

@kvelaro
Copy link
Author

kvelaro commented May 16, 2019

Thank you for you reply!

  1. Yes, I start with verbose DEBUG, and log-file. No error thrown/shown in log.
  2. It would be very difficult to reproduce problem with other language than PHP, because there long logic building arrays.
  3. Why should workers send WORK_COMPLETE, without being started? Tasks which were queued after complete send WORK_COMPLETE.
  4. No, I dont use signals/alarms in PHP

I dont think that gearman server does something to incoming request! and hangs. I think that php_gearman library hangs, I guess there is a bug.

Tailing log file of gearman server I see actions and DEBUG MESSAGES of incoming request and when it hangs I dont see anything, any errors and so on.

@esabol
Copy link
Member

esabol commented May 16, 2019

  1. It would be very difficult to reproduce problem with other language than PHP, because there long logic building arrays.

I would try. First step of debugging is to isolate the issue.

  1. Why should workers send WORK_COMPLETE, without being started? Tasks which were queued after complete send WORK_COMPLETE.

Did I say the workers should send WORK_COMPLETE without being started? No. That’s not even possible, I think. But, just to clarify, none of your workers send exceptions, right?

I think that php_gearman library hangs, I guess there is a bug.

Well, if that’s the case, then, depending on the version of PHP, there are two other GitHub repos for php_gearman where you should open the issue.

Tailing log file of gearman server I see actions and DEBUG MESSAGES of incoming request and when it hangs I dont see anything, any errors and so on.

Does gearmand still respond to requests from other clients when this happens?

@kvelaro
Copy link
Author

kvelaro commented May 30, 2019

Excellent remarks, thanks.

I would try. First step of debugging is to isolate the issue.

No need to try, solved, solution will provide below

But, just to clarify, none of your workers send exceptions, right?

No, no exceptions, no error messages, none. It seemed that request was not delivered to gearmand

there are two other GitHub repos for php_gearman where you should open the issue

I would do it, thx

Does gearmand still respond to requests from other clients when this happens?

Yeah, it did

So my solution (Nothing to do with Gearmand or php extensions):

Intro

We use Yii1, and I cloned repo gearman wrapper - what is known component to Yii world

In config file I have

'gearman' => [
            'class' => 'application.components.Gearman',
            'servers' => [
                ['host' => '127.0.0.1', 'port' => 4730]
            ],
        ],

Ocassionally, I tried to start my loop with bare calls without component, wrapper #first example, and it worked. So forwarded further and found that

foreach ($this->servers as $s)
            {                
                $instance->addServer($s['host'], $s['port']);                
            }

does not work, hovewer it should! Maybe foreach loop is buggy here, I cant explain.
If comment out and write

$mainServer = array_shift($this->servers);
$instance->addServer($mainServer['host'], $mainServer['port']);

It works like a charm.

EDITED:

In main config I have default settings, and gearman with ip (say it A) provided
In local config I have local setting with gearman IP (say it B) provided.

Yii should override main with local, hovewer it seems it doesnt (so foreach maybe not the case)
So happy now, will after test these assumptions

@esabol
Copy link
Member

esabol commented May 30, 2019

I don’t know PHP very well, but, if I do a web search for “PHP foreach not working”, I certainly get a lot of hits. It seems like a fairly common problem. Anyway, I’m glad you found that the problem wasn’t with gearmand. Please close the issue if there is nothing else.

@kvelaro kvelaro closed this as completed May 30, 2019
@dirtyren
Copy link

Hello,
what I have found out that makes doBackground hangs is the fact that PHP running on console wont disconnect from gearmand. Eventually gearmand can no longer accept connections.
I've tried unset or make the object = NULL, it does not matter. It seems, PHP wont call the gearman client destructor that should clean up things. This does not happen when running inside apache, as apache will make certain everything is cleaned.
I've tested this in CentOS 6 PHP 5.4 and CentOS8 PHP 7.4 from REMI Repo, same behavior.
I think PHP gearman client should have a disconnect function, but as long as I am aware, it does not.
The same goes for workers, same behavior, if you keep creating new objects, even is you unset them or make them qual NULL, a PHP connection with port 4730 ( in my case ) will be kept open.
Has anyone observed this ? Tks.

@esabol
Copy link
Member

esabol commented Dec 24, 2020

So the PHP client doesn't disconnect even after the server returns the job result? That sounds like a bug in the PHP library to me. I don't think we've seen that with the Gearman Perl library.

The main issue when talking about the PHP Gearman library is which one? There have been multiple implementations and multiple maintainers, most of whom have stopped maintaining, AFAIK. Honestly, I don't even know where to go to get the latest, best version.

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

3 participants