php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37931 PHP in Apache crash after Database-Restart while using persistent connections
Submitted: 2006-06-27 15:34 UTC Modified: 2006-06-28 15:04 UTC
From: Olaf dot Imig at bifab dot de Assigned:
Status: Closed Package: OCI8 related
PHP Version: 5.1.4 OS: Linux(x86)/Solaris(sparc)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Olaf dot Imig at bifab dot de
New email:
PHP Version: OS:

 

 [2006-06-27 15:34 UTC] Olaf dot Imig at bifab dot de
Description:
------------
The following behavior ist reproduceable:
-Call the script
-shutdown/startup the Database
-Call the script
=> Apache Instance crash

The bug is forced, when you call the script many times. For the tests I used the OCI8 stuff from Oracle8i on Solaris and from Oracle8i and Oracle10g on Linux. The result was the same. Without persistent connection all is perfect.

Perhaps I can deliver a Solution. I made two changes in the code and the bug vanished.
After restart of Database php_oci_connection_ping found invalid connections.
The first problem was here, that the function php_oci_connection_close was called twice, first time triggered through  zend_hash_del(&EG(persistent_list)...
and then through a direct call. The Oracle-C-functions don't like this. Furthermore some pointers was freed twice.
The second problem is the call of OCISessionEnd, when the Connection is invalid. Setting of connection->is_close=0 before calling php_oci_connection_close was helpful in this special case.
On demand I can send my patch.




Reproduce code:
---------------
$db=ociplogon("OPASUSER","OPASPASS","TOPASL");
if(!$db){
    print "Connection failed\n";
    exit;
}
ocilogoff($db);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-27 15:48 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-06-27 16:22 UTC] Olaf dot Imig at bifab dot de
Ok, I made the test with php5.2-20060627143 on Solaris. I found the same result.
 [2006-06-27 16:57 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

Also, I should note that ocilogoff($db) does not do anything with persistent connections, it just ignores them, so this piece of code doesn't make much sense.
 [2006-06-28 08:56 UTC] Olaf dot Imig at bifab dot de
Here my backtrace. When I start with httpd -X the server crash immediately after database restart

 #0  0xa70c228c in kputac () from /opt/oracle/oracle8i/lib/libclntsh.so.8.0
#1  0xa710ccb1 in OCISessionEnd ()
   from /opt/oracle/oracle8i/lib/libclntsh.so.8.0
#2  0xa79cbf43 in php_oci_connection_close (connection=0x824b368)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/ext/oci8/oci8.c:1457
#3  0xa79c99ba in php_oci_pconnection_list_dtor (entry=0x826b4d8)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/ext/oci8/oci8.c:707
#4  0xa7b23bd9 in plist_entry_destructor (ptr=0x826b4d8)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/Zend/zend_list.c:210
#5  0xa7b21590 in zend_hash_del_key_or_index (ht=0xa7c64bd4, 
    arKey=0x823a5b4 "oci8___opasuser__topasl__0", nKeyLength=27, h=513927878, 
    flag=0)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/Zend/zend_hash.c:492
#6  0xa79cad30 in php_oci_do_connect_ex (username=0x823edb4 "OPASUSER", 
    username_len=8, password=0x823a634 "OPASPASS", password_len=8, 
    new_password=0x0, new_password_len=0, dbname=0x823d18c "TOPASL", 
    dbname_len=6, charset=0x0, session_mode=0, persistent=1, exclusive=0)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/ext/oci8/oci8.c:1077
#7  0xa79ca187 in php_oci_do_connect (ht=3, return_value=0x823a6b4, 
    return_value_ptr=0x0, this_ptr=0x0, return_value_used=1, persistent=1, 
    exclusive=0)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/ext/oci8/oci8.c:947
#8  0xa79d9cc7 in zif_oci_pconnect (ht=3, return_value=0x823a6b4, 
    return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/ext/oci8/oci8_interface.c:1536
#9  0xa7b3844c in zend_do_fcall_common_helper_SPEC (execute_data=0xafb2e6f0)
    at zend_vm_execute.h:200
#10 0xa7b3b7ec in ZEND_DO_FCALL_SPEC_CONST_HANDLER (execute_data=0xafb2e6f0)
    at zend_vm_execute.h:1642
#11 0xa7b38003 in execute (op_array=0x823ecf4) at zend_vm_execute.h:92
#12 0xa7b16625 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/Zend/zend.c:1110
#13 0xa7acb122 in php_execute_script (primary_file=0xafb30a80)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/main/main.c:1748
#14 0xa7b85710 in php_handler (r=0x8277d98)
    at /export/home/users/minstall/medea/software/php5.2-200606271430/sapi/apache2handler/sapi_apache2.c:593
#15 0x08067ce9 in ap_invoke_handler ()
#16 0x080656b0 in ap_process_request ()
#17 0x08060bcb in ap_process_http_connection ()
#18 0x08070cca in ap_process_connection ()
#19 0x08066b13 in child_main ()
#20 0x08066bfc in make_child ()
#21 0x08066ffe in ap_mpm_run ()
#22 0x0806cfad in main ()
 [2006-06-28 09:32 UTC] tony2001@php.net
I don't know how did you manage to shutdown Oracle instance when there are active connections and I definitely cannot reproduce it.
Please provide more information.
 [2006-06-28 10:54 UTC] Olaf dot Imig at bifab dot de
Here my procedure. I work on a Linux(x86) system. Webserver and Database are on different computers (communication over TCP!). First I start the webserver with httpd  -X. Then I run my script. netstat show the connection:
tcp       20      0 medea-dev.l.bifab:59019 ramin.l.bifab.de:1521   ESTABLISHED
Then I stop the database:
lsnrctl stop listener
dbshut (with shutdown immediate)
Then I start the database:
dbstart
lsnrctl start listener
After a short time (2-3 min) I call the my script once more.
=>Segmentation fault
 [2006-06-28 14:03 UTC] tony2001@php.net
Does this patch help you?
http://tony2001.phpclub.net/dev/tmp/bug37931.diff
 [2006-06-28 14:47 UTC] Olaf dot Imig at bifab dot de
No, this patch isn't the full solution. Setting connection->is_open to 0 in php_oci_connection_ping is not enough. The server will crash, when php_oci_connection_status
fail. Because of the twice call of  php_oci_connection_close  
after the ping-test the server crash. Its enough to call zend_hash_del(&EG(persistent_list). The destructor of the persistent_list then call php_oci_connection_close. 
Here is my patch (work on php5.2-200606271430)
--- php-5.1.4/ext/oci8/oci8.c.ori	2006-06-26 15:59:03.000000000 +0200
+++ php-5.1.4/ext/oci8/oci8.c	2006-06-27 16:02:28.000000000 +0200
@@ -1065,8 +1065,11 @@
 						}
 					}
 					/* server died */
+					connection->is_open=0;
 					zend_hash_del(&EG(persistent_list), hashed_details.c, hashed_details.len+1);
+					/* one call too much 
 					php_oci_connection_close(connection TSRMLS_CC);
+					*/
 					connection = NULL;
 					goto open;
 				}
 [2006-06-28 15:04 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 01 03:01:29 2025 UTC