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?
ABorka wrote:
win32, latest Lazarus and FPC
Any single web request call works OK, returning the content.
When 2 browsers are open and calling the web module at the same time
there is a crash happening after the 2nd one finishes working (just made
a loop in the web action which lasts a few seconds to have both requests
inside the server at the same time).
Details:
in /fpc/packages/fcl-web/src/fpapache.pp
Function TCustomApacheApplication.ProcessRequest(P: PRequest_Rec) :
Integer;
Var
Req : TApacheRequest;
Resp : TApacheResponse;
begin
Req:=TApacheRequest.CreateReq(Self,P);
Try
Resp:=TApacheResponse.CreateApache(Req);
Try
HandleRequest(Req,Resp); <== call happens here OK but 2nd
concurrent request does not return, gets lost in the ether
Finally
Result:=OK;
Resp.Free;
end;
Finally
Req.Free;
end;
end;
procedure TCustomApacheApplication.HandleRequest(ARequest: TRequest;
AResponse: TResponse);
Var
MC : TCustomHTTPModuleClass;
M : TCustomHTTPModule;
MN : String;
MI : TModuleItem;
begin
try
MC:=Nil;
If (OnGetModule<>Nil) then
OnGetModule(Self,ARequest,MC);
If (MC=Nil) then
begin
MN:=GetModuleName(ARequest);
If (MN='') and Not AllowDefaultModule then
Raise EFPApacheError.Create(SErrNoModuleNameForRequest);
MI:=ModuleFactory.FindModule(MN);
If (MI=Nil) and (ModuleFactory.Count=1) then
MI:=ModuleFactory[0];
if (MI=Nil) then
begin
Raise EFPApacheError.CreateFmt(SErrNoModuleForRequest,[MN]);
end;
MC:=MI.ModuleClass;
end;
M:=FindModule(MC); // Check if a module exists already
If (M=Nil) then
begin
M:=MC.Create(Self);
M.Name := '';//without this there's a crash due to same name
end;
M.HandleRequest(ARequest,AResponse);//calls the web action here,
works OK for both concurrent requests
except
On E : Exception do
ShowRequestException(AResponse,E);
end;
end; <== everything works, but the 2nd concurrent request crashes after
here but before returning to the caller function
A little bit strange that this happens. The return content is prepared
in both simultaneous calls properly. Any thoughts what could be the cause?
AB
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel