php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63647 No signal handling when worker use NON_BLOCKING mode
Submitted: 2012-11-29 13:04 UTC Modified: 2012-12-19 21:56 UTC
From: fruit dot dev at gmail dot com Assigned:
Status: Not a bug Package: gearman (PECL)
PHP Version: Irrelevant OS: FreeBSD 8.1 x64
Private report: No CVE-ID: None
 [2012-11-29 13:04 UTC] fruit dot dev at gmail dot com
Description:
------------
Hello,

When the Gearman worker is running in GEARMAN_WORKER_NON_BLOCKING mode, it 
ignores signals sent to 
PHP script (except KILL signal).

When I use GEARMAN_TIMEOUT instead of NON_BLOCKING, it handles signals 
correctly.

This bug was initially created at 
https://bugs.launchpad.net/gearmand/+bug/1083395 but Gearmand 
maintainer said it's a PECL bug (the comment #3)

Environment: 
  PECL gearman: v1.1.0
  Libgearman: v1.1.3
  PHP: v5.3.10

Test script:
---------------
Test script "gearman_signal_ignore.php": http://pastie.org/5440196

$ php gearman_signal_ignore.php > out.log 2>&1 &
[1] 71643
$ ps aux | grep -v grep | grep gearman_signal_ignore
fruit 71643 0.0 0.5 439920 19252 5 IJ 3:20AM 0:00.11 php gearman_signal_ignore.php
$ kill -INT 71643
$ ps aux | grep -v grep | grep gearman_signal_ignore
fruit 71643 0.0 0.5 439920 19252 5 SJ 3:20AM 0:00.11 php gearman_signal_ignore.php
$ kill -TERM 71643
$ ps aux | grep -v grep | grep gearman_signal_ignore
fruit 71643 0.0 0.5 439920 19252 5 SJ 3:20AM 0:00.11 php gearman_signal_ignore.php
$ kill -KILL 71643
[1]+ Killed: 9 php gearman_signal_ignore.php > out.log 2>&1
$ ps aux | grep -v grep | grep gearman_signal_ignore


Expected result:
----------------
<out.log>
  Working...
  Waiting for next job... (code: 1)
  Working...
  Waiting for next job... (code: 1)
  Working...
  Waiting for next job... (code: 35)
  Signal num: 2 at sigStopChildHandler
</out.log>

I'm expecting for my test script stops as soon as it receives SIGINT or SIGTERM 
signal.

Actual result:
--------------
<out.log>
  Working...
  Waiting for next job... (code: 1)
  Working...
  Waiting for next job... (code: 1)
  Working...
  Waiting for next job... (code: 35)
</out.log>

Test script continues to work even if the SIGINT and SIGTERM was sent to it.

Backtrace: http://pastie.org/5452712

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-19 13:17 UTC] goran dot v dot miskovic at gmail dot com
As mentioned in reply to the initial report at Launchpad the problem is caused by 
the fact that Method GearmanWorker::wait() will wait forever blocking excectuion 
unless the timeout is explicitly set. Default timeout is -1.

You can find working example here: http://pastie.org/5552643

On a side note, consider using pcntl_signal_dispatch instead of declare(ticks=1).
 [2012-12-19 21:56 UTC] hradtke@php.net
-Status: Open +Status: Not a bug
 [2012-12-19 21:56 UTC] hradtke@php.net
Thanks Goran. Closing this out.
 [2012-12-21 12:27 UTC] fruit dot dev at gmail dot com
Thanks for your time and the explanations.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC