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

Michael Van Canneyt michael at freepascal.org
Tue Sep 23 08:44:10 CEST 2008



On Mon, 22 Sep 2008, ABorka wrote:

> After some more debugging the result is even stranger:
> 
> If I reduce the code to the bare minimum there is still a crash most of the
> time.
> 
> 1. works always for 2 concurrent requests:
> procedure TCustomApacheApplication.HandleRequest(ARequest: TRequest;
> AResponse: TResponse);
> Var
>   MC : TCustomHTTPModuleClass;
>   M  : TCustomHTTPModule;
>   MN : String;
>   MI : TModuleItem;
> i:Integer;
> 
> begin
>       MI:=ModuleFactory[0];
>       MC:=MI.ModuleClass;
>       M:=MC.Create(Self);
>       M.Name := '';
> aresponse.content := '<html>Hello</html>';
>       for i := 0 to Maxint do;//time wasting loop, about 5 secs
> end;
> 
> 2. crashes randomly:
> begin
>       MI:=ModuleFactory[0];
>       MC:=MI.ModuleClass;
>       M:=MC.Create(Self);
>       M.Name := '';
> M.HandleRequest(ARequest,AResponse);
>       for i := 0 to Maxint do;//time wasting loop, about 5 secs
> end;//<= sometimes crash after here but before returning to caller function
> 
> 3. always crashes:
> begin
>   try
>       MI:=ModuleFactory[0];
>       MC:=MI.ModuleClass;
>       M:=MC.Create(Self);
>       M.Name := '';
> aresponse.content := '<html>Hello</html>';
>       for i := 0 to Maxint do;//time wasting loop, about 5 secs
>   except
>     On E : Exception do
>       ShowRequestException(AResponse,E);
>   end;
> end;//<= guaranteed crash after here but before returning to caller function
> 
> 
> When M.HandleRequest(ARequest,AResponse); is used instead of aresponse.content
> := '<html>Hello</html>'; the crash is random at procedure return for the 2nd
> simultaneous caller.
> 
> When the procedure contains any try/except it is guaranteed not returning
> (crashing) after the work is finished for the 2nd caller (2nd simultaneaous
> request).
> 
> The first simultaneous caller always works without a problem.
> 
> Any suggestions?

Yes: please print the size of the Request_rec (or TRequest_Rec) and the
same record in C. Compare if they are equal. Same for the module record.
If they are not equal, then we know it is a problem with the pascal 
definition of this record. I've had to do this exercise about 30 times 
myself on various platforms to get it right. Maybe they changed the 
size again.

Michael.



More information about the fpc-devel mailing list