It seems that TidHTTPServer
has a connection leak when connections fail. I have code in the OnException Event to count the current connections:
function TMain.GetCurrentConnectionCount(AWebService: TIdHTTPServer): Integer;
begin
with AWebService.Contexts.LockList do
try
Result:=Count;
finally
AWebService.Contexts.UnlockList;
end;
end;
procedure TMain.WebServiceException(AContext: TIdContext; AException: Exception);
begin
LogWrite('"'+AException.Message+'" in Serversocket in Connection with '+AContext.Binding.PeerIP+':'+IntToStr(AContext.Binding.PeerPort)+'! Current Connectioncount: '+IntToStr(GetCurrentConnectionCount(WebService)), Detailed, TRUE, 'SSL');
try
AContext.Connection.Disconnect;
LogWrite('Connection terminated! Current Connectioncount: '+IntToStr(GetCurrentConnectionCount(WebService)), Detailed, TRUE, 'SSL');
if GetCurrentConnectionCount(WebService)>WebService.MaxConnections-2 then begin
LogWrite('Too many open connections, forcing restart!',Verbose,TRUE,'SSL');
RestartApp;
end;
except
on E: Exception do
LogWrite('"'+E.Message+'" while terminating Connection! Current Connectioncount: '+IntToStr(GetCurrentConnectionCount(WebService)), Detailed, TRUE, 'SSL');
end;
end;
procedure TMain.WebServiceConnect(AContext: TIdContext);
var
Allowedlist, Blockedlist: Boolean;
Port, IP:string;
begin
try
IP:=AContext.Binding.PeerIP;
Port:=IntToStr(AContext.Binding.PeerPort);
LogWrite('New Connection from "'+IP+':'+Port+'"! Current Connectioncount: '+IntToStr(GetCurrentConnectionCount(WebService)), Debug, TRUE, 'SSL');
FFilterListLock.BeginRead;
try
Allowedlist:=Allowlist.IndexOf(IP)>-1;
Blockedlist:=Blocklist.IndexOf(IP)>-1;
finally
FFilterListLock.EndRead;
end;
if not Allowedlist then begin
if Blockedlist then begin
LogWrite('Blocking IP "'+IP+':'+Port+'"!', Detailed, TRUE, 'SSL');
LogRequest(IP, '*BLOCKED*');
AContext.Connection.Disconnect;
SysUtils.Abort;
end;
end else begin
LogWrite('IP "'+IP+':'+Port+'" is whitelisted!', Detailed, TRUE, 'SSL');
end;
except
on E: Exception do begin
if not(E is EAbort)then
LogWrite('"'+E.Message+'" while connection-check on blocklist', Detailed, TRUE, 'SSL')
else
raise;
end;
end;
end;
When I receive exception "Error accepting connection with SSL. EOF was observed that violates the protocol" the connection count does not decrease!
I tried AContext.Connection.Disconnect;
but that didn't help.
Any ideas?
Update1: Added Code for OnException and OnConnect