[fpc-devel] Lazarus Apache module crashes during concurrent requests

Michael Van Canneyt michael at freepascal.org
Wed Sep 24 12:35:51 CEST 2008



On Wed, 24 Sep 2008, ABorka wrote:

> I'm not sure that something is changed to make it incompatible.
> The apache modules compiled on windows are only crashing if multiple requests
> are coming at the same time, and they are crushing at function/procedure
> returns (Yes, on Linux it is even worse, since no module gets even loaded by
> apache. That might be some C API translation problem).
> 
> Even if reduced to this small code it crushes (but only if multiple calls are
> inside this code) on windows:
> ===========================
> Function TCustomApacheApplication.ProcessRequest(P: PRequest_Rec) : Integer;
> 
> Var
>   Req : TApacheRequest;
>   Resp : TApacheResponse;
>   i:integer;
> 
> begin
>   Req:=TApacheRequest.CreateReq(Self,P);
>   Try
>     Resp:=TApacheResponse.CreateApache(Req);
>     Try
> for i := 0 to maxint do ;//Time wasting for multiple requests at the same time
> to run this code
> //      HandleRequest(Req,Resp);
> //      If Not Resp.ContentSent then
> //        Resp.SendContent;
>     Finally
>       Result:=OK;
>       Resp.Free;//<= crashes after here randomly for 2nd simultaneous 
> caller
>     end;
>   Finally
>     Req.Free;
>   end;
> end;
> ==============================
> Sometimes when removing all the try/finally pairs from the function it works.
> But then adding more code, even as simple as DateTimeToStr(Now), makes it
> crash. Sometimes more code can be added but then it will crash inside that
> code somewhere at function/procedure returns.

This is a known problem; the heap manager does not function correctly in a
DLL when an external program (apache, in this case) creates new threads.

Changing the heap manager to the C heap manager (just add 'uses cmem' as the
first line in the project) may solve the problem, but it is not guaranteed; 
there was another bug in the memory manager which prevented that from working 
correctly. Maybe it has been fixed meanwhile.

Michael.



More information about the fpc-devel mailing list