php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59423 GearmanWorker::wait and GearmanWorker::work are spamming the log with warnings.
Submitted: 2010-09-15 17:34 UTC Modified: 2012-08-04 23:47 UTC
From: jhalickman at etsy dot com Assigned: hradtke (profile)
Status: Closed Package: gearman (PECL)
PHP Version: 5.2.9 OS: CentOS
Private report: No CVE-ID: None
 [2010-09-15 17:34 UTC] jhalickman at etsy dot com
Description:
------------
The wait() and work() methods on GearmanWorker were causing 
timeout warnings to be logged very often. This caused our logs 
to be filled up with unnecessary warning logs. I have patched 
our copy of the extension and am submitting that diff back to 
be included in the mainline. 



Reproduce code:
---------------
--- gearman-0.7.0/php_gearman.c	1970-01-01 09:13:08.000000000 +0000
+++ gearman-php-fix/php_gearman.c	2010-09-15 16:40:09.000000000 +0000
@@ -3285,7 +3285,7 @@
 
 	obj->ret= gearman_worker_wait(&(obj->worker));
 
-	if (! PHP_GEARMAN_CLIENT_RET_OK(obj->ret)) {
+	if (! PHP_GEARMAN_CLIENT_RET_OK(obj->ret) && obj->ret != GEARMAN_TIMEOUT) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s",
 			gearman_worker_error(&(obj->worker)));
 		RETURN_FALSE;
@@ -3531,7 +3531,8 @@
 
 	obj->ret= gearman_worker_work(&(obj->worker));
 	if (obj->ret != GEARMAN_SUCCESS && obj->ret != GEARMAN_IO_WAIT &&
-		obj->ret != GEARMAN_WORK_FAIL) {
+		obj->ret != GEARMAN_WORK_FAIL && obj->ret != GEARMAN_TIMEOUT &&
+		obj->ret != GEARMAN_NO_JOBS) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s",
 						 gearman_worker_error(&(obj->worker)));
 		RETURN_FALSE;


Expected result:
----------------
No Logs

Actual result:
--------------
PHP error logs got filled with the following:
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::wait(): 
gearman_wait:timeout reached ...
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::work(): 
gearman_wait:timeout reached ...
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::wait(): 
gearman_wait:timeout reached ...
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::work(): 
gearman_wait:timeout reached ...
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::wait(): 
gearman_wait:timeout reached ...
[17-Sep-2010 09:14:06] WARNING: GearmanWorker::work(): 
gearman_wait:timeout reached ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-07 11:57 UTC] jpm at alertlogic dot com
I can reproduce this problem on a Debian Squeeze VM with the 
dotdeb.org PHP 5.3 packages installed. However, when I receive the 
warning specified here, my worker script crashes.

Here are the package versions:

php5-cli -> 5.3.5-0.dotdeb.1
php5-suhosin -> 5.3.5-0.dotdeb.1

The PHP gearman extension version is 0.7.0, the latest available at 
the time of writing this. It was compiled against the 0.16 version 
of the gearmand libraries.

--Joao
 [2011-04-20 19:25 UTC] eric dot caron at gmail dot com
Would it maybe be more appropriate for the work/wait functions to be wrapped in a try/catch and maintain this level of warning? 70% of me doesn't want these warnings, 30% does - are there any other more common functions similar to this functionality that the behavior should be modeled after?
 [2011-05-04 17:48 UTC] jhalickman at etsy dot com
The problem is this did not throw an exception but wrote to 
the logs. It just filled up the logs.
 [2011-05-15 03:55 UTC] hradtke@php.net
Thank you for the patch.  Don't you want the wait() and work() to still return false on timeout?  I think it would be confusing if those functions are returning true.  Also, how would you ever unblock if a timeout is reached unless wait()/work() return false?
 [2011-08-09 21:31 UTC] jameswfraser at gmail dot com
In gearman-0.8.0, the work function has a second if block, 
which checks the response and returns false without the 
logging, but the wait function does not.

I have modified jhalickman's patch to correct this.

--- gearman-0.8.0/php_gearman.c	2011-05-17 
22:51:44.000000000 +0930
+++ gearman-0.8.0-fixed/php_gearman.c	2011-08-10 
10:36:38.163397253 +0930
@@ -3303,12 +3303,17 @@
 
 	obj->ret= gearman_worker_wait(&(obj->worker));
 
-	if (! PHP_GEARMAN_CLIENT_RET_OK(obj->ret)) {
+	if (! PHP_GEARMAN_CLIENT_RET_OK(obj->ret) &&
+		obj->ret != GEARMAN_TIMEOUT) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"%s",
 			gearman_worker_error(&(obj-
>worker)));
 		RETURN_FALSE;
 	}
 
+	if (! PHP_GEARMAN_CLIENT_RET_OK(obj->ret)) {
+		RETURN_FALSE;
+	}
+
 	RETURN_TRUE;
 }
 
@@ -3554,7 +3559,8 @@
 
 	obj->ret= gearman_worker_work(&(obj->worker));
 	if (obj->ret != GEARMAN_SUCCESS && obj->ret != 
GEARMAN_IO_WAIT &&
-		obj->ret != GEARMAN_WORK_FAIL) {
+		obj->ret != GEARMAN_WORK_FAIL && obj->ret != 
GEARMAN_TIMEOUT &&
+		obj->ret != GEARMAN_NO_JOBS) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"%s",
 						 
gearman_worker_error(&(obj->worker)));
 		RETURN_FALSE;
 [2011-08-15 13:45 UTC] andy at andy-burton dot co dot uk
The GearmanWorker::work(): gearman_con_wait:timeout error is thrown up for me when any of the worker servers added are taken offline. The PHP worker process then crashes.

The effect of this for me is that when a single worker server goes offline the entire set of gearman worker processes timeout and exit, taking the whole thing down.

Is there a fix for this? I'm using ubuntu, php 5.3, gearman-0.8.0 under pecl (latest release)
 [2011-08-16 10:37 UTC] hradtke@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 [2011-09-27 00:38 UTC] eric at linkup dot com
The code in SVN is working great for us. Any chance a 0.8.1 release that would include it?
 [2011-09-27 10:38 UTC] hradtke@php.net
I need to make a change to the configuration and then cut a release. I will make it happen sometime this week.
 [2011-11-12 19:37 UTC] phpnet at krogon dot net
Hello, is there any new release date with changes from svn?
 [2011-11-23 23:57 UTC] matthew dot scott dot day at gmail dot com
after applying the patch, the only difference is that now instead of getting a warning i get nothing, the warning was causing the main worker loop to stop so instead of the worker sitting idle and waiting for a job, it just stops and shows me the command line again.
 [2011-12-05 07:26 UTC] micuenta99 at gmail dot com
Any news about the 0.8.1' release data with this patch included?

Thanks,
 [2011-12-05 16:44 UTC] hradtke@php.net
I released gearman-1.0.1 with this fix.
 [2011-12-07 06:31 UTC] micuenta99 at gmail dot com
In RHEL4 version of libgearman is 0.14.
Is it possible to have a version of Gearman compiled against this version of 
libgearmand and with this bug fixed?

Thanks,
 [2011-12-07 06:32 UTC] micuenta99 at gmail dot com
In RHEL6 version of libgearman is 0.14 too.
 [2011-12-08 23:55 UTC] hradtke@php.net
I just released gearman-0.8.1 that has this fix in it without the new dependencies on gearman-0.21.
 [2011-12-09 09:56 UTC] micuenta99 at gmail dot com
Thank you very much
 [2012-08-03 03:57 UTC] gattm at luxbet dot com
With 0.8.1 we still observed a warning coming from the 'work' method:

Warning: GearmanWorker::work(): (null) in <filename>

Note the absence of any actual error message. This was using libgearman version 0.34. This patch corrected the problem for us:

--- gearman-0.8.1/php_gearman.c	2012-08-03 12:26:52.193736013 +1000
+++ gearman-0.8.1-patched/php_gearman.c	2012-08-03 12:27:30.394733400 +1000
@@ -3562,7 +3562,8 @@
 
 	obj->ret= gearman_worker_work(&(obj->worker));
 	if (obj->ret != GEARMAN_SUCCESS && obj->ret != GEARMAN_IO_WAIT &&
-		obj->ret != GEARMAN_WORK_FAIL && obj->ret != GEARMAN_TIMEOUT) {
+		obj->ret != GEARMAN_WORK_FAIL && obj->ret != GEARMAN_TIMEOUT &&
+		obj->ret != GEARMAN_NO_JOBS) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s",
 						 gearman_worker_error(&(obj->worker)));
 		RETURN_FALSE;


-- Marcus
 [2012-08-03 14:33 UTC] hradtke@php.net
-Status: Closed +Status: Re-Opened
 [2012-08-04 23:47 UTC] hradtke@php.net
-Status: Re-Opened +Status: Closed
 [2012-08-04 23:47 UTC] hradtke@php.net
Fixed. New packages are uploaded here:
http://pecl.php.net/package/gearman
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC