Bug #17044 Updated: TIME_WAIT status

From: Date: Wed, 19 Jun 2002 15:13:05 +0000
Subject: Bug #17044 Updated: TIME_WAIT status
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-11405@lists.php.net to get a copy of this message
ID: 17044 Updated by: gberger@apaara.com Reported By: gberger@apaara.com Status: Open Bug Type: Sockets related Operating System: Linux Red Hat 7.0 PHP Version: 4.2.1 New Comment: as i have discussed with others in the meantime, i think the TIME_WAIT status is not the problem: the process that is opening a tcp-connection from webserv to tixserv needs to stay in TIME_WAIT, in case its last ACK is lost and tixserv sends its FIN again. webserv is acting as client here and has to stay in TIME_WAIT for 2MSL. the thing i do not understad is that in the praticular case described, the tcp connection opened to the browser stays in TIME_WAIT as well; this should not be, since webserv is the server in this case. probably, this is an apache issue. just because i'm curious, fillipo: what kernel and what apache do you use? Previous Comments: ------------------------------------------------------------------------ [2002-06-19 10:46:32] filippo@zirak.it > probably, this is not a php issue anymore. I think it still is a php bug (4.2.1)... even using it as command line script, it seems from netstat that the connection is not well closed... :-( binding, accepting, (shutdowning,) closing a socket on 19731 leave anyway the connection open in TIME_WAIT tcp 0 0 localhost:19731 localhost:32861 TIME_WAIT ------------------------------------------------------------------------ [2002-06-18 02:40:06] gberger@apaara.com i partially agree - have not thought about this yet. well, so i went and turned KeepAlice Off in the apache conf. and yes, the described behaviour went away. so far, so good. but there are still some points that make no sense to me: - the TIME_WAIT status of these tcp connections stays there until timeout (after 2MSL has passed). that should not be the case if i am doing an active close, right? - even with KeepAlive On: in my apache conf, the KeepAliveTimeout Directive is set to 15 seconds. but the tcp connection of httpd stays in ESTABLISHED state for much longer than 15 seconds. this should not happen, right? probably, this is not a php issue anymore. i would be grateful for any pointers, though. btw. i have upgraded to php 4.2.1 in the meantime. ------------------------------------------------------------------------ [2002-06-17 07:16:48] rick@simpleftp.co.uk Are you sure this isn't the keep-alive part of the HTTP protocol? AFAIK, most browsers will use a keep-alive header to keep the connection to the HTTP server open, even after it has received the entire document. That lets it speed things up as it doesn't have to reconnect to load another page, images or whatever. There's details on the settings for it under Apache 1.3 at http://httpd.apache.org/docs/keepalive.html ------------------------------------------------------------------------ [2002-05-13 05:16:21] gberger@apaara.com i have also tried this in a slightly different setting: red hat 7.2, kernel-2.4.7 and php 4.1.2. in this environment, both tcp-connections go right to the TIME_WAIT status and stay there for 1 minute (which seems to be 2MSL); the tcp connection owned by httpd is not waiting in ESTABLISHED mode as it does under kernel 2.2. this seems to be a kernel-related issue, then? has anyone else experienced this problem? ------------------------------------------------------------------------ [2002-05-06 11:48:40] gberger@apaara.com this is my setup: php 4.2.0 with the socket extension, as a dynamically loaded module in apache 1.3.23. it is running on is a red hat 7.0 box with kernel 2.2.19. this is was i am trying to do: i am using the socket functions to connect to a server which is running a ticketing software using a specifically designed protocol; the details do not matter here. i'll call my webserver "webserv.com", the client calling the script "client.com" and the ticketsystem "tixserv.com". i think i am doing everything by the book - just a simple one-shot tcp-client; writing some request to tixserv.com, reading the response and closing the connection. i am using socket_create(), socket_connect(), socket_write(), socket_read(), and finally socket_close(), pretty much the same way as the example 2 ("Simple TCP/IP client") in the php manual. this seems to work well (no errors or warnings). this is my problem: if i monitor the connection attempts with netstat, i am seeing the following behaviour: firstly, connections are established: from webserv.com to client.com and from webserv.com to tixserv.com: tcp webserv.com:1558 tixserv.com:45007 SYN_SENT 1126/httpd tcp webserv.com:www client.com:1894 ESTABLISHED 1126/httpd then, the connection from webserv.com to tixserv.com is closed (using socket_close() in the script), so the connection status goes to TIME_WAIT: tcp webserv.com:1558 tixserv.com:45007 TIME_WAIT - tcp webserv.com:www client.com:1894 ESTABLISHED 1126/httpd i see that to go to TIME_WAIT status is the correct way to behave for a socket. but the problem is that httpd somehow seems to wait for the TIME_WAIT status to go away and keeps the connection open during this time (ESTABLISHED). this takes a really long time (at least 30 seconds or more). at some time, the TIME_WAIT of the connection to tixserv.com finally goes away, and the connection to the client falls into that state: tcp webserv.com:www client.com:1894 TIME_WAIT - strange - my browser and php seem to ignore this: the script execution, measured with microtime(), is around 800 miliseconds, of which at least 90% is response time by tixserv.com which is fine. also, my browser does not need more than a second to display the script results. nonetheless, the httpd connection on the server stays ESTABLISHED for at least 30 seconds. the scary thing about this is that it gets worse if i start to stress the server. i used jakarta-jmeter to simulate simultaneous requests. jmeter did not behave the same as my browser: it actually waited until the httpd connection status was really closed. this totally stressed webserv.com: i had response times around 600 seconds and more, with only 5 threads doing 2 requests for the script. the load on webserv.com was huge during that time, sometimes i even had to stop apache to end the test. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17044&edit=1

« previous php.bugs (#11405) next »