Bug in TROHttpServerApiServer


You can reproduce the bug with the following code:

oServer := TROHttpServerApiServer.Create();
oServer.ThreadCnt := 2; // any <> 1 
oServer.Active := True;

The reason is that worker threads created in UpdateThreads() begin their execution before activating the server, where fReqQueueHandle is initialized.
It leads to ERROR_INVALID_HANDLE in HttpServerAPI.ReceiveHttpRequest and escaping from TROHttpThread.IntExecute.

Best regards


weird, but this code

works w/o any errors.
what I miss?

Hi Evgeny,

works w/o any errors.
what I miss?

the code I proposed doesn’t raise any evident error but it doesn’t mean that all is right.

Currently, TROHttpThread.IntExecute executes just ONCE, because HttpServerAPI.ReceiveHttpRequest returns ERROR_INVALID_HANDLE for fReqQueueHandle=0.

I attached the sample project HttpServerRacing.7z (424 Bytes) and a bit modified TROHttpThread.IntExecute with

OutputDebugString(PChar(Format('TROHttpThread.IntExecute fOwner.fReqQueueHandle = %u', [fOwner.fReqQueueHandle])));

This results the following log in Delphi:

Hope I explained the bug :slight_smile:

IMO to get a robust solution TROHttpThread.IntExecute has to be synched (e.g. with an event) with TROHttpServerApiServer.SetActive.

Best regards

Thanks, logged as bugs://85706

bugs://85706 got closed with status fixed.

update uROHttpServerApiServer.pas as

procedure TROHttpServerApiServer.SetThreadCnt(const Value: Integer);
    if fActive then UpdateThreads(False); //<<<<<<<<changed