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

Segfault when running http://gearman.org/examples/multi-query/ #13

Closed
vladnis opened this issue Mar 16, 2016 · 8 comments
Closed

Segfault when running http://gearman.org/examples/multi-query/ #13

vladnis opened this issue Mar 16, 2016 · 8 comments

Comments

@vladnis
Copy link

vladnis commented Mar 16, 2016

Hi,

I got the following error when running the example form http://gearman.org/examples/multi-query/, with PHP7, and gearman plugin built from master :

Program received signal SIGSEGV, Segmentation fault.
0x00005555557a9de0 in _zval_dtor_func ()
(gdb) bt
#0 0x00005555557a9de0 in _zval_dtor_func ()
#1 0x00007fffed2f4f9a in _zval_dtor (zvalue=)

at /usr/include/php/20151012/Zend/zend_variables.h:44

#2 gearman_task_obj_free (object=0x7ffff386f0f8) at /tmp/gearman/php_gearman.c:3757
#3 0x00005555557e763a in zend_objects_store_del ()
#4 0x00005555557bcc0f in zend_array_destroy ()
#5 0x00007fffed2f52e3 in _zval_dtor (zvalue=)

at /usr/include/php/20151012/Zend/zend_variables.h:44

#6 gearman_client_obj_free (object=0x7ffff38789f8) at /tmp/gearman/php_gearman.c:3609
#7 0x00005555557e763a in zend_objects_store_del ()
#8 0x00005555557be03c in zend_hash_reverse_apply ()
#9 0x000055555579bf05 in shutdown_destructors ()
#10 0x00005555557ab687 in zend_call_destructors ()
#11 0x000055555574b1a5 in php_request_shutdown ()
#12 0x000055555583f579 in ?? ()
#13 0x0000555555636524 in main ()

@brstgt
Copy link

brstgt commented Mar 16, 2016

+1 thanks for the reproducible use case :)

@brstgt
Copy link

brstgt commented Mar 17, 2016

I am not a php-extension expert but I was able to track down the segfault to the following line

static void gearman_task_obj_free(zend_object *object) {
gearman_task_obj *intern = gearman_task_fetch_object(object);
if (!intern) {
return;
}

zval_dtor(&intern->zworkload);
zval_dtor(&intern->zdata);

// zval_dtor(intern->zclient);

zend_object_std_dtor(&intern->std);

}

Commenting out "zval_dtor(intern->zclient);" made the segfault gone. I don't have a deep insight into the gearman module but to me it seems that the zclient property is a weak reference that should not be d'tored. The client holds the list of its tasks but the task should not manage the client reference. Right?

@vladnis
Copy link
Author

vladnis commented Mar 17, 2016

Yes, probably that is the problem. Added a pull request for fix.

@brstgt
Copy link

brstgt commented Mar 17, 2016

I am not sure if the zClient should be destructed at this point at all. The task owns its workload and data but it does not own the client. The client owns the task. I'm not a php-ext expert but this is what my general programming experience says :)

@wcgallego
Copy link
Owner

zval_dtor should only destroy the object fully if the refcount is 0. We might need to include an zref_add every time we use this object.

Just for my own sanity as I sort through these, can you try the latest build to see if you can replicate? I know you said you were going to need a few days first.

@wcgallego
Copy link
Owner

hey @vladnis, I merged a bunch of fixes from other pull requests. I did make a minor fix in which GearmanWorker::addServer's params should be optional, but otherwise the pull requests elsewhere seem to have fixed the multi-query example. Can you grab HEAD and test again on your end? thanks!

@vladnis
Copy link
Author

vladnis commented Mar 18, 2016

The Segfault is resolved. But, I saw that if you left addServer to get defaults parameters, it does not seem to connect to 127.0.0.1:4730. It rather remains blocked. I can close this bug. Should I create a new one for the above problem? Thanks.

@vladnis vladnis closed this as completed Mar 18, 2016
@wcgallego
Copy link
Owner

No, I'll just patch that up real fast :) thanks!

Update: @vladnis can you actually open up an issue? I'm actually able to use the defaults when creating a worker. localhost:4730, right?

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