php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18515 Apache2filter hangs on DNS request
Submitted: 2002-07-23 17:38 UTC Modified: 2002-09-09 01:00 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:4 (100.0%)
From: ryan at estara dot com Assigned:
Status: No Feedback Package: Apache2 related
PHP Version: 4.3.0-dev OS: Redhat 7.2
Private report: No CVE-ID: None
 [2002-07-23 17:38 UTC] ryan at estara dot com
I submitted this bug in a previous version, it still exists and is driving me crazy.  Last time it was dismissed and I never followed up because I found a work around.  Here is the issue:

PHP 4.2.2 configured with:
./configure --prefix=/prod/apache/php --with-apxs2=/prod/apache/bin/apxs --with-mysql --with-gd 

Apache 2.0.39 configured with:
./configure --prefix=/prod/apache --enable-layout=Apache --enable-ssl=shared --enable-vhost-alias=shared --enable-proxy=shared --enable-rewrite=shared --with-mpm=worker --enable-info=shared --disable-userdir --enable-so=max --enable-mods-shared

Try to get this php script that connects to a mysql database:
<?php
session_start();
echo "session id is ".session_id()."<br>\n";
echo "Testing: $testing<br>\n";

    $link = mysql_connect("my.database.com", "username", "password")
        or die("Could not connect");
    print ("Connected successfully");

$db_name = "dbname";
$table_name = "tablename";

$select_db = mysql_select_db($db_name, $link);

$query = "SELECT Name FROM $table_name"; 
$result = mysql_query($query, $link) or die("Could not complete database query");
$num = mysql_num_rows($result);
while ($row = mysql_fetch_row ($result))
{ 
        print "Value stored at the first index position is $row[0]<br>"; 
}
mysql_close($link);

?>

Make sure nscd is not running and the "my.database.com" is not in the /etc/hosts file.  The server will hang...  the odd thing is that if you don't include libgd support it will work.  Something is screwy and I haven't been able to track it down.  Here is where it hangs though:

#0  0x402cc996 in __sigsuspend (set=0xbf5fd85c) at ../sysdeps/unix/sysv/linux/sigsuspend.c:45
#1  0x40290d6d in __pthread_wait_for_restart_signal (self=0xbf5ffc00) at pthread.c:969
#2  0x40292863 in __pthread_lock (lock=0x400157fc, self=0xbf5ffc00) at restart.h:34
#3  0x4028efdd in __pthread_mutex_lock (mutex=0x400157ec) at mutex.c:109
#4  0x403b1728 in _dl_open (file=0xbf5fdb1c "libnss_dns.so.2", mode=1, caller=0x0) at dl-open.c:401
#5  0x403b267e in do_dlopen (ptr=0xbf5fdaec) at dl-libc.c:78
#6  0x4000ce55 in _dl_catch_error (objname=0xbf5fdae4, errstring=0xbf5fdae8, operate=0x403b265c <do_dlopen>, args=0xbf5fdaec)
    at dl-error.c:152
#7  0x403b252e in __libc_dlopen (__name=0xbf5fdb1c "libnss_dns.so.2") at dl-libc.c:42
#8  0x403937c7 in __nss_lookup_function (ni=0x80fa400, fct_name=0x403c6e6e "gethostbyname_r") at nsswitch.c:340
#9  0x40394304 in __nss_next (ni=0xbf5fdc4c, fct_name=0x403c6e6e "gethostbyname_r", fctp=0xbf5fdc50, status=-1, all_values=0)
    at nsswitch.c:194
#10 0x40396ce9 in __gethostbyname_r (name=0x81b9564 "reports.estara.com", resbuf=0x403d1620, buffer=0x81b7168 "\177", buflen=1024, 
    result=0xbf5fdc90, h_errnop=0xbf5fdc94) at ../nss/getXXbyYY_r.c:215
#11 0x403966da in gethostbyname (name=0x81b9564 "my.database.com") at ../nss/getXXbyYY.c:131
#12 0x40529eb7 in mysql_real_connect () from /prod/mysql/lib/mysql/libmysqlclient.so.10
#13 0x4045038e in php_mysql_do_connect (ht=3, return_value=0x81b95ec, this_ptr=0x0, return_value_used=1, tsrm_ls=0x8173370, 
    persistent=0) at php_mysql.c:662
#14 0x40450588 in zif_mysql_connect (ht=3, return_value=0x81b95ec, this_ptr=0x0, return_value_used=1, tsrm_ls=0x8173370)
    at php_mysql.c:714
#15 0x4041d8b8 in execute (op_array=0x81b45ec, tsrm_ls=0x8173370) at ./zend_execute.c:1598
#16 0x4042c562 in zend_execute_scripts (type=8, tsrm_ls=0x8173370, retval=0x0, file_count=3) at zend.c:810
#17 0x40439b12 in php_execute_script (primary_file=0xbf5ff92c, tsrm_ls=0x8173370) at main.c:1381
#18 0x40436455 in php_output_filter (f=0x819e040, bb=0x819e238) at sapi_apache2.c:401
#19 0x08087daf in ap_pass_brigade (next=0x819e040, bb=0x819e170) at util_filter.c:534
#20 0x0808e06c in default_handler (r=0x816f3b0) at core.c:3276
#21 0x0807dc62 in ap_run_handler (r=0x816f3b0) at config.c:193
#22 0x0807e11d in ap_invoke_handler (r=0x816f3b0) at config.c:373
#23 0x0806cb23 in ap_process_request (r=0x816f3b0) at http_request.c:257
#24 0x08068d15 in ap_process_http_connection (c=0x816d480) at http_core.c:291
#25 0x08086386 in ap_run_process_connection (c=0x816d480) at connection.c:85
#26 0x0807afca in process_socket (p=0x816d370, sock=0x816d3a8, my_child_num=0, my_thread_num=0, bucket_alloc=0x816b2f8)
    at worker.c:631
#27 0x0807b57d in worker_thread (thd=0x810b2d0, dummy=0x8168940) at worker.c:945
#28 0x40212644 in dummy_worker (opaque=0x810b2d0) at thread.c:127
#29 0x4028df87 in pthread_start_thread (arg=0xbf5ffc00) at manager.c:284

The work around I'm using is putting the database name in the /etc/hosts file and that appears to be working.  It's really wacky.  The scripts run fine with the standalone version of php so it's definatly the interaction with apache. (sapi/apache2filter)

Thanks,
-Ryan

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-23 18:33 UTC] ryan at estara dot com
Also this will prevent resolution of hostnames in mod_rewrite say you have have that configuration in your apache config and add a rewrite rule of:

RewriteEngine on
RewriteRule ^/magik(.*)         http://www.magik.net$1 [P]

it will hang on the lookup of 'www.magik.net'.  It does not hang, however, if you comment out the line where you load the php module.
 [2002-07-23 18:33 UTC] ryan at estara dot com
Also this will prevent resolution of hostnames in mod_rewrite say you have have that configuration in your apache config and add a rewrite rule of:

RewriteEngine on
RewriteRule ^/magik(.*)         http://www.magik.net$1 [P]

it will hang on the lookup of 'www.magik.net'.  It does not hang, however, if you comment out the line where you load the php module.
 [2002-07-23 20:56 UTC] sniper@php.net
reclassified
 [2002-07-23 20:56 UTC] sniper@php.net
You should also try the latest CVS versions of both Apache2 and PHP..

 [2002-07-24 01:09 UTC] ryan at estara dot com
Same thing happens with PHP-4.3.0-dev with Apache 2.0.4-dev as of the lastest and greatest from both late last week.  Are you not able to reproduce this?
 [2002-07-29 16:39 UTC] ryan at estara dot com
When apache is compiled with mpm=prefork this bug does not exist.  It does exist when mpm=worker or mpm=threadpool.

-Ryan
 [2002-07-30 06:03 UTC] rasmus@php.net
So it is clearly an issue of something not being threadsafe somewhere in there.  Perhaps in libgd as you mention that specifically, but who knows.  Thread safety issues like this are very difficult to track down.  There will be hundreds of similar problems which is one of the main reasons that Apache2 in anything but prefork mode and PHP are not going to be a viable production-quality solution for a very very long time.  (read years)
 [2002-07-30 21:52 UTC] sniper@php.net
libmysqlclient lib is not the thread-safe?

mysql configure has this option:
--enable-thread-safe-client

btw, that backtrace had some lines about '/prod/mysql/lib/mysql/libmysqlclient.so.10' so you're NOT
using the bundled mysql?

Or to try configure the bundled mysql lib thread-safe:

CFLAGS=-DTHREAD_SAFE_CLIENT ./configure <your options>


 [2002-08-01 18:25 UTC] ryan at magik dot net
Yeah, I read the mysql issue before.  I did however try using the bundled mysql as well as the libmysqlclient_r.  In this particular case '/prod/mysql/lib/mysql/libmysqlclient.so.10' is a symbolic link to the _r library for mysql.  Also things works fine as long as the libgd isn't included as well.

Sorry for the confusion about that.  

Compiled with the most recent option suggestions it still has the same issue and dies in the same place.

CFLAGS=-DTHREAD_SAFE_CLIENT ./configure --prefix=/prod/apache/php --with-apxs2=/prod/apache/bin/apxs --with-mysql --with-gd --without-readline --enable-debug

(gdb) bt
#0  0x402cbbb5 in __sigsuspend (set=0x40acf7fc) at ../sysdeps/unix/sysv/linux/sigsuspend.c:45
#1  0x402901d9 in __pthread_wait_for_restart_signal (self=0x40ad1be0) at pthread.c:969
#2  0x40291a2c in __pthread_lock (lock=0x4001649c, self=0x40ad1be0) at spinlock.c:149
#3  0x4028ed46 in __pthread_mutex_lock (mutex=0x4001648c) at mutex.c:109
#4  0x403b6e50 in _dl_open (file=0x40acfabc "libnss_dns.so.2", mode=1, caller=0x0) at dl-open.c:401
#5  0x403b7ce1 in do_dlopen (ptr=0x40acfa8c) at dl-libc.c:78
#6  0x4000d7c3 in _dl_catch_error (objname=0x40acfa84, errstring=0x40acfa88, operate=0x403b7cc0 <do_dlopen>, args=0x40acfa8c)
    at dl-error.c:152
#7  0x403b7b8c in __libc_dlopen (__name=0x40acfabc "libnss_dns.so.2") at dl-libc.c:42
#8  0x40398eff in __nss_lookup_function (ni=0x80f9ff8, fct_name=0x403cc50e "gethostbyname_r") at nsswitch.c:340
#9  0x40399866 in __nss_lookup (ni=0x40acfb8c, fct_name=0x403cc50e "gethostbyname_r", fctp=0x40acfb90) at nsswitch.c:147
#10 0x4039a80c in __nss_hosts_lookup (ni=0x40acfb8c, fct_name=0x403cc50e "gethostbyname_r", fctp=0x40acfb90) at XXX-lookup.c:70
#11 0x4039c227 in __gethostbyname_r (name=0x81b3308 "reports.estara.com", resbuf=0x403d6ca0, buffer=0x819cc08 "", buflen=1024, 
    result=0x40acfbd0, h_errnop=0x40acfbd4) at ../nss/getXXbyYY_r.c:168
#12 0x4039bbad in gethostbyname (name=0x81b3308 "hostname") at ../nss/getXXbyYY.c:131
#13 0x404806e7 in mysql_real_connect (mysql=0x81b3490, host=0x81b3308 "hostname", user=0x81b3390 "username", 
    passwd=0x81b3410 "password", db=0x0, port=3306, unix_socket=0x0, client_flag=0) at libmysql.c:1307
#14 0x40479e95 in php_mysql_do_connect (ht=3, return_value=0x81b3450, this_ptr=0x0, return_value_used=1, tsrm_ls=0x817d3f0, 
    persistent=0) at php_mysql.c:662
#15 0x4047a1f7 in zif_mysql_connect (ht=3, return_value=0x81b3450, this_ptr=0x0, return_value_used=1, tsrm_ls=0x817d3f0)
    at php_mysql.c:714
#16 0x40433304 in execute (op_array=0x81b0440, tsrm_ls=0x817d3f0) at ./zend_execute.c:1598
#17 0x40445cfd in zend_execute_scripts (type=8, tsrm_ls=0x817d3f0, retval=0x0, file_count=3) at zend.c:810
#18 0x40458fb9 in php_execute_script (primary_file=0x40ad18ac, tsrm_ls=0x817d3f0) at main.c:1381
#19 0x40454575 in php_output_filter (f=0x81aa288, bb=0x81a7f60) at sapi_apache2.c:401
#20 0x08087daf in ap_pass_brigade (next=0x81aa288, bb=0x81aa3b8) at util_filter.c:534
#21 0x0808e06c in default_handler (r=0x8179430) at core.c:3276
#22 0x0807dc62 in ap_run_handler (r=0x8179430) at config.c:193
#23 0x0807e11d in ap_invoke_handler (r=0x8179430) at config.c:373
#24 0x0806cb23 in ap_process_request (r=0x8179430) at http_request.c:257
#25 0x08068d15 in ap_process_http_connection (c=0x8175488) at http_core.c:291
#26 0x08086386 in ap_run_process_connection (c=0x8175488) at connection.c:85
#27 0x0807afca in process_socket (p=0x8175378, sock=0x81753b0, my_child_num=0, my_thread_num=0, bucket_alloc=0x816b190)
    at worker.c:631
#28 0x0807b57d in worker_thread (thd=0x810af58, dummy=0x8168770) at worker.c:945
#29 0x40213644 in dummy_worker (opaque=0x810af58) at thread.c:127
#30 0x4028dc6f in pthread_start_thread (arg=0x40ad1be0) at manager.c:284
#31 0x4028dd5f in pthread_start_thread_event (arg=0x40ad1be0) at manager.c:308

I think rasmus@php.net was pretty on target, I'll take a shot at making libgd in php mt safe and see where that gets me.
 [2002-09-09 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, 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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC