Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Jan : Re: TIdCustomHTTPServer - Abandoned threads

www.cryer.info
Managed Newsgroup Archive

Re: TIdCustomHTTPServer - Abandoned threads

Subject:Re: TIdCustomHTTPServer - Abandoned threads
Posted by:"Mike B." (mbrickm..@radsol.co.uk)
Date:30 Jan 2007 04:27:45

Thanks for that.

You are correct - the problem seems to be clients that are not
disconnecting properly.  They just go away which leaves the thread
waiting forever. This is a very public website taking hundreds of hits
per hour, so it's entirely possible that there are some proxy servers
out there that just don't bother to tell us they have gone away.

To fix the problem I have set the ReadTimeOut to 5mins when the
context is created - as follows:

    constructor TMyContext.Create(aConnection: TIdTCPConnection;
aYarn: TIdYarn; aList: TIdThreadList = nil);
    begin
      aConnection.IOHandler.ReadTimeOut := 300000; {5 mins}
      ...
      inherited;
    end;

This sort of works, but fires an assert trap in
TIdCustomHTTPServer.DoExecute - Assert(not IOHandler.ReadLnTimedOut).
This is rather irritating as assertions are difficult to handle as
they are too unspecific.  For my purposes, I have simply replace the
assert function with an exit clause as follows:

    function TIdCustomHTTPServer.DoExecute(AContext:TIdContext):
boolean;
    ...
    begin
      ...
      LInputLine := IOHandler.ReadLn;
      if IOHandler.ReadLnTimedOut then begin
        exit;
      end;
    ...

It would be better if a timeout condition raised a specific exception
which could then be trapped and handled as appropriate.  Eg:

    function TIdCustomHTTPServer.DoExecute(AContext:TIdContext):
boolean;
    ...
    begin
      ...
      LInputLine := IOHandler.ReadLn;
      if IOHandler.ReadLnTimedOut then begin
        raise EIdHTTPTimeout.Create(RSHTTPTimeout);
      end;
    ...

How do we request this to the team?

Thanks in advance

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive