php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44614 signal handlers fail to execute when signal interrupts a socket_select
Submitted: 2008-04-02 15:24 UTC Modified: 2008-08-15 01:00 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: dan at auctionharmony dot com Assigned:
Status: No Feedback Package: PCNTL related
PHP Version: 5.2.6RC3 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-04-02 15:24 UTC] dan at auctionharmony dot com
Description:
------------
When waiting in a socket_select (and presumably a stream_select, but I have not tested it) a previously set signal handler is not executed when a signal is received.  The select returns false as would be expected.

The analog code in C is also attached.  It correctly executes the signal handler.

Tested on PHP 5.1.6(CentOS), 5.2.6_rc1(Gentoo), 5.2.6-rc3(Gentoo)

Reproduce code:
---------------
//PHP: when SIGINT is recieved, socket_select returns false, sig_handler is not run
pcntl_signal(SIGINT, "sig_handler");
$sock = socket_create_listen($port);
$read_socks = array($sock);
$n = NULL;
$foo = socket_select($read_socks, $n, $n, NULL);

//C: when SIGINT is recieved, select returns -1, sig_handler is run
signal(SIGINT, sig_handler);
int sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr);
listen(sockfd, 10);

fd_set read_fds;
FD_ZERO(&read_fds);
FD_SET(sockfd, &read_fds);

select(sockfd+1, &read_fds, NULL, NULL, NULL)


Expected result:
----------------
I expect the result to be like the equivalent C where the signal handler is run and select returns error.

Actual result:
--------------
Select returns false, but unlike the equivalent C the signal handler is not run

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-07 15:59 UTC] lbarnaud@php.net
I can't reproduce with the following code:

<?php
declare(ticks=1);

function sig_handler($signo) {
        echo __FUNCTION__ . " called\n";
}
pcntl_signal(SIGINT, "sig_handler");

$socket = socket_create_listen(1234);
$read = array($socket);
$n = NULL;
$foo = socket_select($read, $n, $n, NULL);
?>

The signal handler is called just after socket_select returns.

 [2008-08-15 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat May 25 15:01:27 2019 UTC