From pete-tbnl-dev at kazmier.com Fri Jul 16 14:44:03 2004 From: pete-tbnl-dev at kazmier.com (pete-tbnl-dev at kazmier.com) Date: Fri, 16 Jul 2004 10:44:03 -0400 Subject: [mod-lisp-devel] Re: [tbnl-devel] Odd behavior (socket leak) Message-ID: <20040716144403.GC7050@kazmier.com> This bounced the first time I sent it to the list because I was not subscribed. ----- Forwarded message from pete-tbnl-dev at kazmier.com ----- From: pete-tbnl-dev at kazmier.com To: edi at agharta.de Cc: pete-tbnl-dev at kazmier.com, tbnl-devel at common-lisp.net, mod-lisp-devel at common-lisp.net Subject: Re: [tbnl-devel] Odd behavior (socket leak) On Fri, Jul 16, 2004 at 12:37:49PM +0200, edi at miles wrote: > I'm sitting in a train and trying to send this via my cell > phone. Let's see if it works... :) Nice :-) > I've looked at the source code of mod_lisp.c (version 2.33) and Apache > (1.3.29) and I'm beginning to ask myself whether the "Keep-Socket" > option makes any sense at all. What I see with my limited knowledge of > Apache is the following: You missed one key part of the process. > 2. To get a socket, lisp-handler calls OpenLispSocket. > > 3. OpenLispSocket uses ap_psocket (using the global variable > SocketPool) to get a socket from Apache. OpenLispSocket only fetches a new socket if and only if one has not already established and is safe to use (see here): if (cfg->LispSocket) if (cfg->UnsafeLispSocket) { ap_pclosesocket(SocketPool, cfg->LispSocket); cfg->LispSocket = 0; cfg->UnsafeLispSocket = 0; } else { return cfg->LispSocket; } This is the step that bypasses the creation of a new socket. Thus, Keep-Socket does make sense. I'll continue looking at the TBNL and mod_Lisp interaction to see if I can find anything else. Thanks, Pete ----- End forwarded message ----- From pete-tbnl-dev at kazmier.com Fri Jul 16 16:31:07 2004 From: pete-tbnl-dev at kazmier.com (pete-tbnl-dev at kazmier.com) Date: Fri, 16 Jul 2004 12:31:07 -0400 Subject: [mod-lisp-devel] Re: [tbnl-devel] Odd behavior (socket leak) In-Reply-To: <20040715212252.GA29894@kazmier.com> References: <20040715212252.GA29894@kazmier.com> Message-ID: <20040716163107.GA7402@kazmier.com> On Thu, Jul 15, 2004 at 05:22:52PM -0400, pete-tbnl-dev at kazmier.com wrote: > In any case, I've been banging my head all day, I need a break, but it > would be appreciated if someone could either confirm or deny the opening > of multiple sockets while never closing any of the old ones. Its easy > to see via a 'netstat -an | grep 3000' (or whatever port you run it on). Upon further thought, isn't this behavior to be expected? I.e. as requests come into Apache, and Apache dispatches them to one or more of its children (processes/threads), doesn't each child via the mod_lisp handler create its own connection to TBNL on port 3000? And since Keep-Socket is "1", this is the reason why I never see any of the sockets closing. Thus, I should expect to see a socket for every child Apache process/thread, right? Or does mod_lisp make sure the same socket is used for all cases? This does not appear to be the case as I do see TBNL accept more than one connection on port 3000. Obviously, I'm not very familiar with the Apache API or mod_lisp. Back to my original problem, I'm still a little confused as to why I can't get a simple page that includes 3 style links (irrelevant I suspect other than it does cause multiple requests to occur in a very short amount of time perhaps on different sockets from the client) in it to load properly under any combination of mod_lisp, TBNL and lisp implementation. I've tried using SBCL, CMUCL, Apache 1.x (w/ modlisp-2.33), Apache 2.x (w/ modlisp for 2.x Apache). The symptom is the same, the web browser just sits there and hangs until the mod_lisp module times out reading from TBNL. Debugging the mod_lisp module seems to indicate that mod_lisp just sits there waiting for a response from TBNL. This seems to only occur for one of the four initial requests that it sent to TBNL (one of the style links). My only guess is that perhaps TBNL is somehow writing its response to the wrong *apache-stream* as mod_lisp handler does open multiple connections to TBNL on port 3000. I'm new to lisp and I'm not quite sure how special variables work in a multithreaded app or one that uses the CMUCL event loop. I look forward to your return Edi for some enlightenment! :-) Thanks, Pete From edi at agharta.de Sat Jul 17 10:48:18 2004 From: edi at agharta.de (Edi Weitz) Date: Sat, 17 Jul 2004 12:48:18 +0200 (CEST) Subject: [mod-lisp-devel] Re: [tbnl-devel] Odd behavior (socket leak) Message-ID: <2024.217.81.19.199.1090061298.squirrel@217.81.19.199> [Looks like it didn't work the first time with common-lisp.net - maybe due to my misconfiguration of SquirrelMail. I'll try it again. Note that Peter has already pointed out my mistaken assumption.] I'm sitting in a train and trying to send this via my cell phone. Let's see if it works... :) I've looked at the source code of mod_lisp.c (version 2.33) and Apache (1.3.29) and I'm beginning to ask myself whether the "Keep-Socket" option makes any sense at all. What I see with my limited knowledge of Apache is the following: 1. The actual content handler in mod_lisp.c which is called each time a new request comes in (from the client) is the function lisp_handler. 2. To get a socket, lisp-handler calls OpenLispSocket. 3. OpenLispSocket uses ap_psocket (using the global variable SocketPool) to get a socket from Apache. 4. ap_psocket is defined in Apache's src/main/alloc.c and basically just calls ap_psocket_ex. 5. ap_socket_ex always unconditionally acquires a new socket via socket(7). The pool which is its first argument (and which is SocketPool from above) is only used for cleanup purposes. So, as a consequence, I cannot understand if and how the socket used by lisp_handler is ever going to be re-used. I'm sending a copy of this email to mod-lisp-devel because Marc is the authoritative source for this kind of questions... :) Cheers, Edi. From marc.battyani at fractalconcept.com Sat Jul 17 11:04:06 2004 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sat, 17 Jul 2004 13:04:06 +0200 Subject: [mod-lisp-devel] Re: [tbnl-devel] Odd behavior (socket leak) References: <2024.217.81.19.199.1090061298.squirrel@217.81.19.199> Message-ID: <042901c46bed$c80ddf30$0a02a8c0@marcxp> Hi Edi, "Edi Weitz" wrote: >[Looks like it didn't work the first time with common-lisp.net - maybe due >to my misconfiguration of SquirrelMail. I'll try it again. Note that Peter >has already pointed out my mistaken assumption.] > >I'm sitting in a train and trying to send this via my cell >phone. Let's see if it works... :) > >I've looked at the source code of mod_lisp.c (version 2.33) and Apache >(1.3.29) and I'm beginning to ask myself whether the "Keep-Socket" option >makes any sense at all. What I see with my limited knowledge of Apache is >the following: > >1. The actual content handler in mod_lisp.c which is called each time > a new request comes in (from the client) is the function > lisp_handler. > >2. To get a socket, lisp-handler calls OpenLispSocket. > >3. OpenLispSocket uses ap_psocket (using the global variable > SocketPool) to get a socket from Apache. > >4. ap_psocket is defined in Apache's src/main/alloc.c and basically > just calls ap_psocket_ex. > >5. ap_socket_ex always unconditionally acquires a new socket via > socket(7). The pool which is its first argument (and which is > SocketPool from above) is only used for cleanup purposes. > >So, as a consequence, I cannot understand if and how the socket used by >lisp_handler is ever going to be re-used. > >I'm sending a copy of this email to mod-lisp-devel because Marc is the >authoritative source for this kind of questions... :) Hi Edi, in OpenLispSocket: If there is a socket in cfg->LispSocket and that socket is not unsafe (cfg->UnsafeLispSocket) then I return this socket. I don't create a new one. Re-using the socket is much faster. if (cfg->LispSocket) if (cfg->UnsafeLispSocket) { ap_pclosesocket(SocketPool, cfg->LispSocket); cfg->LispSocket = 0; cfg->UnsafeLispSocket = 0; } else return cfg->LispSocket; Or did I mis-read your question ? Cheers, Marc From edi at agharta.de Sun Jul 18 15:37:11 2004 From: edi at agharta.de (Edi Weitz) Date: Sun, 18 Jul 2004 17:37:11 +0200 (CEST) Subject: [mod-lisp-devel] Socket leaks, again Message-ID: <35019.212.23.126.4.1090165031.squirrel@212.23.126.4> [Again, I'm in a train and sending via cell phone and GPRS. Let's see if it works better this time. Also, I'm not sure if SquirrelMail will be able to keep indentations.] I'm prepared to make myself a fool in public again. I've debugged the mod_lisp/Apache interaction (by inserting log statements in strategic places) a bit and here's what I found out (Linux x86, mod_lisp 2.33, Apache 1.3.29, CMUCL 18e): 1. Whenever OpenLispSocket is called, cfg->LispSocket is 0. This can be best seen if you start Apache with the -X option so that you only one child process. This would imply that sockets can never be re-used. 2. Another data point (see also Peter's earlier post) is that netstat -an | grep 3000 reports far more established connections than there are Apache child processes. 3. I guess this is due to the fact that the configuration record is reset by Apache on each request. I observe that the comment in Apache's example module (which is also in mod_lisp) says "Note that while the per-directory and per-server configuration records are available to most of the module handlers, they should be treated as READ-ONLY by all except the command and merge handlers. Sometimes handlers are handed a record that applies to the current location by implication or inheritance, and modifying it will change the rules for other locations." This is obviously violated by mod_lisp which modifies the record in the content handler. 4. My na?ve attempt to fix this is to make LispSocket and UnsafeLispSocket global variables. A patch which reflects my changes is attached at the bottom. This currently works for me. Debugging shows that sockets are in fact re-used this time. Also, if I benchmark with ApacheBench (2000 request, 200 concurrent, 1300 byte static page, client and server on same machine) then the original mod_lisp code is able to handle roughly 140 requests per seconds while my modified code handles more than 460 requests per seconds. 5. Of course, this patch will only work if the Apache children are separate processes spawned by the server process as with Apache 1.3, i.e. another approach must be taken for the new, alternative Apache 2.0 thread implementations. OK, that's all for now. Let me know what you think. Cheers, Edi. --- /home/edi/downloads/Lisp/mod_lisp-2.33.c 2004-07-16 01:52:23.000000000 +0200 +++ mod_lisp-2.33.c 2004-07-18 16:58:23.000000000 +0200 @@ -189,10 +189,11 @@ char LispServerIP[20]; long LispServerPort; char LispServerId[100]; - long LispSocket; - long UnsafeLispSocket; } excfg; +static long LispSocket = 0; +static long UnsafeLispSocket = 0; + pool *SocketPool = NULL; /* @@ -371,13 +372,6 @@ if (lisp_pool == NULL) { lisp_pool = ap_make_sub_pool(NULL); }; - /* - * Likewise for the table of routine/environment pairs we visit outside of - * request context. - */ - if (static_calls_made == NULL) { - static_calls_made = ap_make_table(lisp_pool, 16); - }; } #endif @@ -421,21 +415,21 @@ int ret; #ifndef WIN32 - if (cfg->LispSocket) - if (cfg->UnsafeLispSocket) + if (LispSocket) + if (UnsafeLispSocket) { - ap_pclosesocket(SocketPool, cfg->LispSocket); - cfg->LispSocket = 0; - cfg->UnsafeLispSocket = 0; + ap_pclosesocket(SocketPool, LispSocket); + LispSocket = 0; + UnsafeLispSocket = 0; } else { - return cfg->LispSocket; + return LispSocket; } #endif - cfg->LispSocket = 0; - cfg->UnsafeLispSocket = 0; + LispSocket = 0; + UnsafeLispSocket = 0; addr.sin_addr.s_addr = inet_addr(cfg->LispServerIP); addr.sin_port = htons((unsigned short) cfg->LispServerPort); addr.sin_family = AF_INET; @@ -459,7 +453,7 @@ if (ret == -1) return -1; - cfg->LispSocket = sock; + LispSocket = sock; return sock; } @@ -498,13 +492,13 @@ if (Socket != -1) ap_pclosesocket(SocketPool, Socket); #else - if (!cfg->LispSocket) + if (!LispSocket) return; - ap_pclosesocket(SocketPool, cfg->LispSocket); + ap_pclosesocket(SocketPool, LispSocket); - cfg->LispSocket = 0; - cfg->UnsafeLispSocket = 0; + LispSocket = 0; + UnsafeLispSocket = 0; #endif } @@ -605,7 +599,7 @@ } ap_reset_timeout(r); - dcfg->UnsafeLispSocket = 1; + UnsafeLispSocket = 1; if (r->subprocess_env) { @@ -860,7 +854,7 @@ ap_bpushfd(BuffSocket, -1, -1); /* unlink buffer to keep socket */ BuffSocket->flags &= ~B_SOCKET; } - dcfg->UnsafeLispSocket = 0; + UnsafeLispSocket = 0; return OK; } @@ -985,7 +979,6 @@ strcpy(cfg->LispServerId, "apache"); cfg->LispServerPort = 3000; cfg->DefaultLispServer = 1; - cfg->LispSocket = 0; cfg->cmode = CONFIG_MODE_DIRECTORY; dname = (dname != NULL) ? dname : ""; @@ -1059,7 +1052,6 @@ merged_config->DefaultLispServer = 1; } - merged_config->LispSocket = 0; return (void *) merged_config; } @@ -1087,7 +1079,6 @@ strcpy(cfg->LispServerIP, "127.0.0.1"); strcpy(cfg->LispServerId, "apache"); cfg->LispServerPort = 3000; - cfg->LispSocket = 0; cfg->DefaultLispServer = 1; sname = (sname != NULL) ? sname : ""; cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL); @@ -1148,7 +1139,6 @@ merged_config->DefaultLispServer = 1; } - merged_config->LispSocket = 0; return (void *) merged_config; } @@ -1309,7 +1299,6 @@ cfg->LispServerId[99] = 0; cfg->LispServerPort = atoi(port); cfg->DefaultLispServer = 0; - cfg->LispSocket = 0; return NULL; } From marc.battyani at fractalconcept.com Sun Jul 18 17:10:13 2004 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 18 Jul 2004 19:10:13 +0200 Subject: [mod-lisp-devel] Socket leaks, again References: <35019.212.23.126.4.1090165031.squirrel@212.23.126.4> Message-ID: <09b701c46cea$184293e0$0a02a8c0@marcxp> Edi wrote: >[Again, I'm in a train and sending via cell phone and GPRS. Let's see >if it works better this time. Also, I'm not sure if SquirrelMail will >be able to keep indentations.] > >I'm prepared to make myself a fool in public again. Heh?? Reporting and fixing problems is not really what I would call making oneself a fool in public. ;-) > I've debugged the >mod_lisp/Apache interaction (by inserting log statements in strategic >places) a bit and here's what I found out (Linux x86, mod_lisp 2.33, >Apache 1.3.29, CMUCL 18e): > >1. Whenever OpenLispSocket is called, cfg->LispSocket is 0. This can > be best seen if you start Apache with the -X option so that you > only one child process. This would imply that sockets can never be > re-used. > >2. Another data point (see also Peter's earlier post) is that > > netstat -an | grep 3000 > reports far more established connections than there are Apache > child processes. > >3. I guess this is due to the fact that the configuration record is > reset by Apache on each request. I observe that the comment in > Apache's example module (which is also in mod_lisp) says > > "Note that while the per-directory and per-server configuration > records are available to most of the module handlers, they > should be treated as READ-ONLY by all except the command and > merge handlers. Sometimes handlers are handed a record that > applies to the current location by implication or inheritance, > and modifying it will change the rules for other locations." > > This is obviously violated by mod_lisp which modifies the record in > the content handler. > >4. My na?ve attempt to fix this is to make LispSocket and > UnsafeLispSocket global variables. A patch which reflects my > changes is attached at the bottom. This currently works for > me. Debugging shows that sockets are in fact re-used this > time. Also, if I benchmark with ApacheBench (2000 request, 200 > concurrent, 1300 byte static page, client and server on same > machine) then the original mod_lisp code is able to handle roughly > 140 requests per seconds while my modified code handles more than > 460 requests per seconds. This was how I originally wrote the socket reuse code, (with LispSocket and UnsafeLispSocket as global variables) but then when I tried to port it to windows it was failing because Apache is multi-threaded on windows. So I tried to be more clean and moved the variables to the config struct. This still didn't worked for windows, this is why there is an #ifndef WIN32 around the reuse code. After that I just verified that it was still ok on Linux but I didn't redo the socket reuse and speed tests. >5. Of course, this patch will only work if the Apache children are > separate processes spawned by the server process as with Apache > 1.3, i.e. another approach must be taken for the new, alternative > Apache 2.0 thread implementations. Yes, Apache 1.3 has separate processes on Linux so going back to global variables is ok for me. >OK, that's all for now. Let me know what you think. I think: Good catch! I looked at your patches, they look ok for me so I commited them to the mod_lisp repository and switched my servers to mod_lisp 2.35. Please get the latest one (2.35) on the mod_lisp repository: http://www.fractalconcept.com:8000/public/open-source/ Cheers, Marc From edi at agharta.de Sat Jul 17 23:07:09 2004 From: edi at agharta.de (Edi Weitz) Date: Sun, 18 Jul 2004 01:07:09 +0200 Subject: [mod-lisp-devel] Re: [tbnl-devel] Odd behavior (socket leak) In-Reply-To: <042901c46bed$c80ddf30$0a02a8c0@marcxp> (Marc Battyani's message of "Sat, 17 Jul 2004 13:04:06 +0200") References: <2024.217.81.19.199.1090061298.squirrel@217.81.19.199> <042901c46bed$c80ddf30$0a02a8c0@marcxp> Message-ID: <87smbqgrmq.fsf@bird.agharta.de> Hi Marc! On Sat, 17 Jul 2004 13:04:06 +0200, "Marc Battyani" wrote: > in OpenLispSocket: > > If there is a socket in cfg->LispSocket and that socket is not > unsafe (cfg->UnsafeLispSocket) then I return this socket. I don't > create a new one. Re-using the socket is much faster. > > if (cfg->LispSocket) > if (cfg->UnsafeLispSocket) > { > ap_pclosesocket(SocketPool, cfg->LispSocket); > cfg->LispSocket = 0; > cfg->UnsafeLispSocket = 0; > } > else > return cfg->LispSocket; > > Or did I mis-read your question ? No, you didn't, it was just an oversight of mine. Sorry for the noise, Edi. From edi at agharta.de Sun Jul 18 18:29:57 2004 From: edi at agharta.de (Edi Weitz) Date: Sun, 18 Jul 2004 20:29:57 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again Message-ID: <87d62tp3ru.fsf@bird.agharta.de> Hi Marc! I managed to delete your email I wanted to reply to but I'll try to copy the relevant parts from the c-l.net archive... :) > Heh?? Reporting and fixing problems is not really what I would call > making oneself a fool in public. ;-) Well, I wasn't so sure. I missed spectaclularly with my last one... :) > I think: Good catch! I looked at your patches, they look ok for me > so I commited them to the mod_lisp repository and switched my > servers to mod_lisp 2.35. OK, cool. Why, by the way, is it 2.35 and not 2.34? According to the mod_lisp website the latest release was 2.33 (which is also the one from Debian). > Please get the latest one (2.35) on the mod_lisp repository: > http://www.fractalconcept.com:8000/public/open-source/ I get no reply when I try to connect... :( Cheers, Edi. From marc.battyani at fractalconcept.com Sun Jul 18 20:12:39 2004 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 18 Jul 2004 22:12:39 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again References: <87d62tp3ru.fsf@bird.agharta.de> Message-ID: <0a4e01c46d03$93d38960$0a02a8c0@marcxp> Edi Weitz wrote: > > I think: Good catch! I looked at your patches, they look ok for me > > so I commited them to the mod_lisp repository and switched my > > servers to mod_lisp 2.35. > > OK, cool. Why, by the way, is it 2.35 and not 2.34? According to the > mod_lisp website the latest release was 2.33 (which is also the one > from Debian). Hum, this web site is poorly maintained... :( I change it from time to time, when I find some time. The trouble is that these days, when I find some time, I prefer hacking cl-typesetting or something like that rather than updating the web site... > > Please get the latest one (2.35) on the mod_lisp repository: > > http://www.fractalconcept.com:8000/public/open-source/ > > I get no reply when I try to connect... :( I restarted Apache2 (used by svn), it's ok for me now. Cheers, Marc From edi at agharta.de Mon Jul 19 10:47:16 2004 From: edi at agharta.de (Edi Weitz) Date: Mon, 19 Jul 2004 12:47:16 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again In-Reply-To: <0a4e01c46d03$93d38960$0a02a8c0@marcxp> (Marc Battyani's message of "Sun, 18 Jul 2004 22:12:39 +0200") References: <87d62tp3ru.fsf@bird.agharta.de> <0a4e01c46d03$93d38960$0a02a8c0@marcxp> Message-ID: <87d62sff4b.fsf@bird.agharta.de> On Sun, 18 Jul 2004 22:12:39 +0200, "Marc Battyani" wrote: > Hum, this web site is poorly maintained... :( I change it from time > to time, when I find some time. The trouble is that these days, when > I find some time, I prefer hacking cl-typesetting or something like > that rather than updating the web site... I'll add a link to the SVN repository to the TBNL docs. >> > Please get the latest one (2.35) on the mod_lisp repository: >> > http://www.fractalconcept.com:8000/public/open-source/ >> >> I get no reply when I try to connect... :( > > I restarted Apache2 (used by svn), it's ok for me now. Yep, it worked briefly last night but tomorrow again the connection is refused... :( Cheers, Edi. From edi at agharta.de Mon Jul 19 12:13:23 2004 From: edi at agharta.de (Edi Weitz) Date: Mon, 19 Jul 2004 14:13:23 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again In-Reply-To: <87d62sff4b.fsf@bird.agharta.de> (Edi Weitz's message of "Mon, 19 Jul 2004 12:47:16 +0200") References: <87d62tp3ru.fsf@bird.agharta.de> <0a4e01c46d03$93d38960$0a02a8c0@marcxp> <87d62sff4b.fsf@bird.agharta.de> Message-ID: <87llhgp53w.fsf@bird.agharta.de> On Mon, 19 Jul 2004 12:47:16 +0200, Edi Weitz wrote: > Yep, it worked briefly last night but tomorrow again the connection > is refused... :( Oh my, I wanted to say "today" of course... :) From marc.battyani at fractalconcept.com Mon Jul 19 17:11:29 2004 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Mon, 19 Jul 2004 19:11:29 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again References: <87d62tp3ru.fsf@bird.agharta.de><0a4e01c46d03$93d38960$0a02a8c0@marcxp> <87d62sff4b.fsf@bird.agharta.de> Message-ID: <0c8601c46db3$6faf4eb0$0a02a8c0@marcxp> Edi Weitz wrote: > I'll add a link to the SVN repository to the TBNL docs. Good. > >> > Please get the latest one (2.35) on the mod_lisp repository: > >> > http://www.fractalconcept.com:8000/public/open-source/ > >> > >> I get no reply when I try to connect... :( > > > > I restarted Apache2 (used by svn), it's ok for me now. > > Yep, it worked briefly last night but tomorrow again the connection is > refused... :( I'm checking it now and it's ok for me. Do you still have connection problems ? Cheers, Marc From edi at agharta.de Mon Jul 19 17:17:23 2004 From: edi at agharta.de (Edi Weitz) Date: Mon, 19 Jul 2004 19:17:23 +0200 Subject: [mod-lisp-devel] Re: Socket leaks, again In-Reply-To: <0c8601c46db3$6faf4eb0$0a02a8c0@marcxp> (Marc Battyani's message of "Mon, 19 Jul 2004 19:11:29 +0200") References: <87d62tp3ru.fsf@bird.agharta.de> <0a4e01c46d03$93d38960$0a02a8c0@marcxp> <87d62sff4b.fsf@bird.agharta.de> <0c8601c46db3$6faf4eb0$0a02a8c0@marcxp> Message-ID: <874qo3diho.fsf@bird.agharta.de> On Mon, 19 Jul 2004 19:11:29 +0200, "Marc Battyani" wrote: > I'm checking it now and it's ok for me. Do you still have connection > problems ? No, it works now. Thanks, Edi. From edi at agharta.de Tue Jul 20 10:40:26 2004 From: edi at agharta.de (Edi Weitz) Date: Tue, 20 Jul 2004 12:40:26 +0200 Subject: [mod-lisp-devel] "Leaked children" Message-ID: <87ekn79d2d.fsf@bird.agharta.de> Hi! Again, a little patch. This time it's not about leaked sockets but rather about "leaked children," so to say. It was Stefan Scholl who actually prompted me to investigate this further and here's what I found out: This piece of code if (ReadLength < ContentLength || r->connection->aborted) { char buffer[HUGE_STRING_LEN]; ContentLength -= ReadLength; do { ReadLength = ForceGets(buffer, (BUFF *) BuffSocket, HUGE_STRING_LEN > ContentLength ? ContentLength : HUGE_STRING_LEN); ContentLength -= ReadLength; } while (ReadLength > 0 && ContentLength > 0); } doesn't work if ContentLength is large enough. What's happening is that the process of emptying BuffSocket (the loop above) always hangs when exactly the last 8192 (HUGE_STRING_LEN) bytes are waiting to be removed. I tried with ap_bread instead of ForceGets but got the same result. (Note that ap_bgets which is used by ForceGets does CR/LF handling which is not needed here.) The result is that this child becomes unusable but is still there, it is never killed by the Apache root process. An easy way to reproduce this (with TBNL) is to do (asdf:oos 'asdf:load-op :tbnl-test) (tbnl:start-test) with a proper Apache configuration (see TBNL docs) and then call ApacheBench with large values like so: ab -n 2000 -c 200 http://localhost/tbnl/test/image.jpg (The important point is that image.jpg is big enough - about 20kB in this case.) After doing this you'll see a large number of Apache processes with ps(1) and the same amount of Lisp processes from within your Lisp image. Call ApacheBench often enough (two or three times) and Apache will completely stop to respond because it has reached its 'MaxClient' limit of 150 (unless you've changed it, of course) but none of the 150 clients is usable. This happens because ApacheBench will abort all pending connections as soons as its finished with its tests. The pattern can obviously be used as a DoS attack on mod_lisp. Now, what to do? One option would probably be to set a timeout before emptying the buffer (not tested). But I think the better (and faster) solution is to get rid of the buffer and the socket as well. The next time the client is used we'll have to open up a new socket to Lisp but this won't need 300 seconds (the default Apache value for 'Timeout'). So... if (ReadLength < ContentLength || r->connection->aborted) { ap_log_error("mod_lisp", 0, APLOG_WARNING|APLOG_NOERRNO, r->server, "Could not send complete body to client, closing socket to Lisp"); ap_bclose(BuffSocket); KeepSocket = 0; LispSocket = 0; } The appended patch also adds a couple of braces to appease gcc and it removes some code that is never used at all. Hope that's OK. Cheers, Edi. -------------- next part -------------- A non-text attachment was scrubbed... Name: mod_lisp.patch Type: text/x-patch Size: 7734 bytes Desc: not available URL: From marc.battyani at fractalconcept.com Tue Jul 20 19:37:08 2004 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Tue, 20 Jul 2004 21:37:08 +0200 Subject: [mod-lisp-devel] mod_lisp 2.36 References: <87d62tp3ru.fsf@bird.agharta.de><0a4e01c46d03$93d38960$0a02a8c0@marcxp><87d62sff4b.fsf@bird.agharta.de><0c8601c46db3$6faf4eb0$0a02a8c0@marcxp> <874qo3diho.fsf@bird.agharta.de> Message-ID: <104201c46e90$f30259a0$0a02a8c0@marcxp> mod_lisp version 2.36 is on the mod_lisp repository: http://www.fractalconcept.com:8000/public/open-source/ Version 2.36 Close Lisp socket (and buffer) if connection is aborted. Some cleanup. (Edi Weitz) Thanks Edi :) Marc