> For some reason sometimes with slow/WAN connections, when clients are
> remote, this code does not work and the client object is "hung",
eventually
> filling the maximum number of connections.

Calling Shutdown will initiate the TCP session shutdown, that is breaking
cleanly the connection. But if for some reason the other party doesn't
receive the shudown request, the connection will stay there forever. You
should probably implement a timeout feature. If you called Shutdown and
don't get the sessionc closed gracefully within some time, then you should
abort the connection.

--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

----- Original Message ----- 
From: "Fastream Technologies" <[EMAIL PROTECTED]>
To: "ICS support mailing" <twsocket@elists.org>
Sent: Wednesday, March 14, 2007 8:28 AM
Subject: [twsocket] Bug in MT THttpConnection close logic


> Hello,
>
> I have a modified THttpServer called THttpMTServer. In thic component,
there
> are worker threads which are pooled and connection objects
> (THttpMTConnection) which are also pooled. I have the following code
called
> from ConnectionDataSent:
>
> void __fastcall httpServerClientClass::ConnectionDataSent(TObject *Sender,
> WORD Error)
> {
>  if(!FDocStream)
>   return;
>
>  if(DataSent >= DataToBeSent || Error)
>  {
>   this->Error = Error;
>
>   endOfResponse();
>
>   return;
>  }
>
> ...
>
> Now in endOfResponse():
>
> void __fastcall httpServerClientClass::endOfResponse(void)
> {
>  if(CGIISAPIInAction)
>  {
>   scheduledToDestroy = true;
>   return;
>  }
>
>  if(responseEnded)
>   return;
>
>  responseEnded = true;
> ...
>
> if(FSessionClosedFlag)
>  {
>   if(pendingHeaderAvailable && availableDataBufferLen <= 2)
>   {
>    pendingHeaderAvailable = false;
>    availableDataBufferLen = 0;
>    availableDataBuffer.SetLength(0);
>   }
>  }
>  else if(!KeepAlive || Error)
>   Shutdown(1);
>  }
>
> Also in OnClientDisconnected:
>
> void __fastcall httpServerThread::HTTPServerClientDisconnected(TObject
> *Sender, TObject *Client, WORD Error)
> {
>  httpServerClientClass *clientObject = (httpServerClientClass*)Client;
>
> ...
>
>  clientObject->Error = Error;
>
>  clientObject->endOfResponse();
>  clientObject->beginDetach();
> }
>
//--------------------------------------------------------------------------
-
>
> and in beginDetach():
>
> void __fastcall httpServerClientClass::beginDetach(void)
> {
>  if(CGIISAPIInAction)
>  {
>   scheduledToDestroy = true;
>   return;
>  }
>
>  if(!detachBegan)
>  {
>   detachBegan = true;
>
>   while(!PostThreadMessage(affinityThread->ThreadID,
> WM_HTTP_CLIENT_THREAD_DETACH, (WPARAM)this, 0))
>    ::Sleep(1);
>  }
> }
>
//--------------------------------------------------------------------------
-
>
> For some reason sometimes with slow/WAN connections, when clients are
> remote, this code does not work and the client object is "hung",
eventually
> filling the maximum number of connections. I have a strong feeling that
> under some circumstances, the OnClientDisconnected is not being called. Or
> maybe there is something else wrong. (BTW, the flags such as detachBegan
are
> correctly reset after each THREAD_ATTACH.)
>
> BR,
>
> Gorkem
>
> -- 
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://www.elists.org/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to