Bug 202537

Summary: php crashing when mysql database cannot be connected to
Product: [Fedora] Fedora Reporter: Reuben Farrelly <reuben-redhatbugzilla>
Component: phpAssignee: Joe Orton <jorton>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-05-17 10:56:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Reuben Farrelly 2006-08-14 23:21:18 UTC
Due to a non-live server migration I am involved with right now, I have 
migrated a MySQL database from one host to another.  However although the 
database has been migrated, the php application using the database has not.  I 
am therefore connecting to my MySQL database across the local network via TCP.

This normally works fine, however I have noticed that php reacts badly when 
the remote database cannot be contacted.  Typically it SIGSEGV's.

In the case I have a backtrace for, the database simply is shut down and port 
3306 refuses connections, but a similar thing happens if the remote host does 
not accept the connection and times out.  php tries to connect to the database 
multiple times before aborting in a smoking great heap:

(gdb) run /var/www/html/cacti.reub.net/poller.php
Starting program: /usr/bin/php /var/www/html/cacti.reub.net/poller.php
[Thread debugging using libthread_db enabled]
[New Thread 47901911282912 (LWP 22322)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47901911282912 (LWP 22322)]
execute (op_array=0x1319068) at /usr/include/bits/string3.h:96
warning: Source file is more recent than executable.
96        return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
(gdb) bt full
#0  execute (op_array=0x1319068) at /usr/include/bits/string3.h:96
        execute_data = {opline = 0x0, function_state = {function_symbol_table 
= 0x3cc0f48980, function = 0x58, reserved = {0x40, 
      0x1093620, 0x7fffa2437d50, 0x7fffa2437d50}}, fbc = 0x0, op_array = 0x40, 
object = 0x0, Ts = 0x7fffa1c3ffb0, 
  CVs = 0x7fffa1c3ff60, original_in_execution = 64 '@', symbol_table = 0x40, 
prev_execute_data = 0x7fffa1c41820, 
  old_error_reporting = 0x0}
#1  0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c41820)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x1093620
        original_return_value = (zval **) 0x7fffa1c41be8
        current_scope = (zend_class_entry *) 0x1064408
        current_this = (zval *) 0x1698ca8
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#2  0x0000000000593adc in execute (op_array=0x1318ee8) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x1093620, function_state = 
{function_symbol_table = 0x1699688, function = 0x1319068, reserved = {
      0x40, 0x11cad80, 0x7fffa2437d50, 0x7fffa2437d50}}, fbc = 0x1319068, 
op_array = 0x1318ee8, object = 0x1698ca8, 
  Ts = 0x7fffa1c40c30, CVs = 0x7fffa1c40bc0, original_in_execution = 1 '\001', 
symbol_table = 0x1699428, 
  prev_execute_data = 0x7fffa1c41db0, old_error_reporting = 0x0}
#3  0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c41db0)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11caee8
        original_return_value = (zval **) 0x7fffa1c42088
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#4  0x0000000000593adc in execute (op_array=0x11c78f0) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11caee8, function_state = 
{function_symbol_table = 0x1699428, function = 0x1318ee8, reserved = {
      0x3cc0c73c5c, 0x50, 0x3cc0f48980, 0x1699220}}, fbc = 0x1318ee8, op_array 
= 0x11c78f0, object = 0x1698ca8, 
  Ts = 0x7fffa1c419b0, CVs = 0x7fffa1c41980, original_in_execution = 1 '\001', 
symbol_table = 0x1698f28, 
  prev_execute_data = 0x7fffa1c422a0, old_error_reporting = 0x0}
#5  0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c422a0)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11de920
        original_return_value = (zval **) 0x7fffa1c424e0
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#6  0x0000000000593adc in execute (op_array=0x11df290) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11de920, function_state = 
{function_symbol_table = 0x1698f28, function = 0x11c78f0, reserved = {
      0x1, 0x11eda98, 0x1698d38, 0x0}}, fbc = 0x0, op_array = 0x11df290, 
object = 0x0, Ts = 0x7fffa1c41f40, CVs = 0x7fffa1c41f10, 
  original_in_execution = 1 '\001', symbol_table = 0x1698b38, 
prev_execute_data = 0x7fffa1c43260, old_error_reporting = 0x0}
#7  0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c43260)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11edb40
        original_return_value = (zval **) 0x7fffa1c437b8
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#8  0x0000000000593adc in execute (op_array=0x11f2dd0) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11edb40, function_state = 
{function_symbol_table = 0x1698b38, function = 0x11df290, reserved = {
      0x1698af8, 0x1, 0x509dd6, 0x28}}, fbc = 0x0, op_array = 0x11f2dd0, 
object = 0x0, Ts = 0x7fffa1c42460, CVs = 0x7fffa1c42400, 
  original_in_execution = 1 '\001', symbol_table = 0x16988d8, 
prev_execute_data = 0x7fffa1c437f0, old_error_reporting = 0x0}
#9  0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c437f0)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11cbb90
        original_return_value = (zval **) 0x7fffa1c43ac8
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#10 0x0000000000593adc in execute (op_array=0x11c78f0) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11cbb90, function_state = 
{function_symbol_table = 0x16988d8, function = 0x11f2dd0, reserved = {
      0x3cc0c73c5c, 0x50, 0x3cc0f48980, 0x1698690}}, fbc = 0x11f2dd0, op_array 
= 0x11c78f0, object = 0x0, Ts = 0x7fffa1c433f0, 
  CVs = 0x7fffa1c433c0, original_in_execution = 1 '\001', symbol_table = 
0x1698418, prev_execute_data = 0x7fffa1c43ce0, 
  old_error_reporting = 0x0}
#11 0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c43ce0)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11de920
        original_return_value = (zval **) 0x7fffa1c43f20
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#12 0x0000000000593adc in execute (op_array=0x11df290) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11de920, function_state = 
{function_symbol_table = 0x1698418, function = 0x11c78f0, reserved = {
      0x1, 0x11eda98, 0x1697618, 0x0}}, fbc = 0x0, op_array = 0x11df290, 
object = 0x0, Ts = 0x7fffa1c43980, CVs = 0x7fffa1c43950, 
  original_in_execution = 1 '\001', symbol_table = 0x1698038, 
prev_execute_data = 0x7fffa1c44ca0, old_error_reporting = 0x0}
#13 0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c44ca0)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
        opline = (zend_op *) 0x11edb40
        original_return_value = (zval **) 0x7fffa1c451f8
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = <value optimized out>
        should_change_scope = 1 '\001'
#14 0x0000000000593adc in execute (op_array=0x11f2dd0) at /usr/src/debug/php-
5.1.4/Zend/zend_vm_execute.h:92
        execute_data = {opline = 0x11edb40, function_state = 
{function_symbol_table = 0x1698038, function = 0x11df290, reserved = {
      0x1697ff8, 0x1, 0x509dd6, 0x28}}, fbc = 0x0, op_array = 0x11f2dd0, 
object = 0x0, Ts = 0x7fffa1c43ea0, CVs = 0x7fffa1c43e40, 
  original_in_execution = 1 '\001', symbol_table = 0x1697dd8, 
prev_execute_data = 0x7fffa1c45230, old_error_reporting = 0x0}
#15 0x00000000005a30a9 in zend_do_fcall_common_helper_SPEC 
(execute_data=0x7fffa1c45230)
    at /usr/src/debug/php-5.1.4/Zend/zend_vm_execute.h:234
    
Quit
(gdb)

An strace of this looks like this:

(noting that the connection refused section below iterates over a few times - 
this is the end of the strace)

connect(3, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr
("192.168.0.8")}, 16) = -1 EINPROGRESS (Operation now in progress)
fcntl(3, F_SETFL, O_RDWR)               = 0
poll([{fd=3, events=POLLIN|POLLPRI, revents=POLLIN|POLLERR|POLLHUP}], 1, 
60000) = 1
setsockopt(3, SOL_IP, IP_TOS, [8], 4)   = 0
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
poll([{fd=3, events=POLLIN, revents=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1
read(3, 0x132f280, 16384)               = -1 ECONNREFUSED (Connection refused)
shutdown(3, 2 /* send and receive */)   = -1 ENOTCONN (Transport endpoint is 
not connected)
close(3)                                = 0
nanosleep({0, 400000000}, NULL)         = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl(3, F_SETFL, O_RDONLY)             = 0
fcntl(3, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(3, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
connect(3, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr
("192.168.0.8")}, 16) = -1 EINPROGRESS (Operation now in progress)
fcntl(3, F_SETFL, O_RDWR)               = 0
poll([{fd=3, events=POLLIN|POLLPRI, revents=POLLIN|POLLERR|POLLHUP}], 1, 
60000) = 1
setsockopt(3, SOL_IP, IP_TOS, [8], 4)   = 0
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
poll([{fd=3, events=POLLIN, revents=POLLIN|POLLERR|POLLHUP}], 1, 60000) = 1
read(3, 0x132f280, 16384)               = -1 ECONNREFUSED (Connection refused)
shutdown(3, 2 /* send and receive */)   = -1 ENOTCONN (Transport endpoint is 
not connected)
close(3)                                = 0
nanosleep({0, 400000000}, NULL)         = 0
brk(0x1370000)                          = 0x1370000
brk(0x1391000)                          = 0x1391000
brk(0x13b2000)                          = 0x13b2000
brk(0x13d3000)                          = 0x13d3000
brk(0x13f4000)                          = 0x13f4000
brk(0x1415000)                          = 0x1415000
brk(0x1436000)                          = 0x1436000
brk(0x1457000)                          = 0x1457000
brk(0x147a000)                          = 0x147a000
brk(0x149b000)                          = 0x149b000
brk(0x14c7000)                          = 0x14c7000
brk(0x14e8000)                          = 0x14e8000
brk(0x1509000)                          = 0x1509000
brk(0x152a000)                          = 0x152a000
brk(0x154b000)                          = 0x154b000
brk(0x156c000)                          = 0x156c000
mmap(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x2ab0ec22e000
brk(0x158d000)                          = 0x158d000
brk(0x15ae000)                          = 0x15ae000
brk(0x15cf000)                          = 0x15cf000
brk(0x15f0000)                          = 0x15f0000
mmap(NULL, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x2ab0ec24f000
brk(0x1611000)                          = 0x1611000
brk(0x1632000)                          = 0x1632000
brk(0x1653000)                          = 0x1653000
brk(0x1674000)                          = 0x1674000
brk(0x1695000)                          = 0x1695000
brk(0x16b6000)                          = 0x16b6000
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 22288 detached
[root@tornado bin]#

While clearly the network connectivity aspect is a problem, this polling 
process is run via cron and therefore I get an autogenerated cron failure 
message every time this job runs and fails due to the SIGSEGV.  But the real 
cause is that php should not be crashing out like that even if the network is 
not working, surely......

[root@tornado bin]# php -v
PHP 5.1.4 (cli) (built: Jul 12 2006 18:28:57) 
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
[root@tornado bin]#

Comment 1 Joe Orton 2006-12-14 15:34:34 UTC
Is this sstill reproducible with the FC5/6 php?

Comment 2 Reuben Farrelly 2006-12-17 09:43:40 UTC
Seems to be better now, at least not crashing, but timing out instead.  This is
with current Rawhide.  Ideally a warning message as output would be good, but at
least now we're not aborting in the same nasty way.

In light of that I guess it's fine to close this bug.


Comment 3 Joe Orton 2007-05-17 10:56:51 UTC
Probably fixed in the upgrade to 5.1.6 - can't reproduce any problems when
running the cacti poller.php with mysqld stopped, with the current FC6 php.