You know a Lazarus developer from Indy team?!
I'm the only developer left on the team. Other remaining members are admins.
I found the place where the problem is generated, in the IdHTTP unit there is the function
function TIdCustomHTTP.Get(AURL: string
{$IFDEF STRING_IS_ANSI}; ADestEncoding: IIdTextEncoding = nil{$ENDIF}
): string;
begin
Result := Get(AURL, []{$IFDEF STRING_IS_ANSI}, ADestEncoding{$ENDIF});
end;
It happens that if the server receives two simultaneous calls it closes. This is on linux and on mac osx. Only I do not understand how to solve. Some idea?
What 2 calls are you referring to? There is only 1
GET request in that code. Just one overloaded
Get() calling another overloaded
Get() with extra parameters. But only 1
GET request is sent to the server.
Ok, I've done other tests and I understand that the problem is not the GET call, the problem is that the http server crashes when idhttpserver1.OnCommandGet is called the second time but has not finished running the first one yet.
What kind of crash EXACTLY? What is your logging telling you?
TIdHTTPServer (like all of Indy's TCP servers) is a multi-threaded component. The
OnCommandGet event (and other events) is triggered in the context of a worker thread for a particular client (represented by the
AContext parameter).
OnCommandGet can be called multiple times in parallel, but only when receiving requests from multiple clients. For a given client, the events are serialized, and HTTP is a command/response protocol, so it is simply not possible for
OnCommandGet to be called for a client while it is already running for that same client. But, it can certainly be called for another client. A browser can (and frequently does) make multiple TCP connections to a server. That is perfectly normal. It is your responsibility to make sure the code in your event handlers is thread-safe.
I modified the source, if you open it you will see that now there is a sleep (4000); in order to give you time to load the page in the browser the second time.
That merely blocks a client from responding for 4 seconds. If you ask your browser to make a new request while the previous request is still blocked, the browser will simply open a new TCP connection to the server (thus running a new thread in the server) to make that new request.