hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: How to interrupt connexion ?
Date Thu, 03 Jul 2003 20:38:42 GMT
Laura,
In my infamous 1.1.8 fork I implemented an ugly, but very effective
solution. I have two threads: a communication thread and an observer
thread. The observer thread simply closes the damn socket when the user
hits the cancel button. Whuuuuuch. The communication thread immediately
throws an IOException and happily terminates. There's almost 100%
certainty that the server will not receive the request in its entirety.

I also attempt to cleanly shutdown input/output streams ob the socket
when running on JDK 1.3 and higher (where such feature is available),
prior to forcefully closing the socket. It works just fine for me.

Cheers

Oleg


On Thu, 2003-07-03 at 22:12, Laura Werner wrote:
> Oleg Kalnichevski wrote:
> 
> >Sadly enough, there's (there will be) no reliable way to interrupt a
> >request in the release 2.0. It is an unfortunate oversight on our part.
> >This feature is planned for the 2.1 release:
> >  
> >
> This is a hard problem, because almost all of the calls in the old 
> java.io library are non-interruptible.  There's no good way to, for 
> example, have a background thread whose job is to interrupt requests 
> that have taken too long.  In our current code, we fake interruptible 
> threads by using (pooled) background threads to execute the requests.  
> When the timeout interval expires, we give up on waiting for the 
> background thread to finish the fetch and just throw a timeout 
> exception.  But I haven't found a way to make the background thread 
> actually stop the fetch, so it just sits there until the socket timeout 
> (if any) triggers an IOException.  At that point we can recycle the 
> thread back into the pool.  This is very error-prone, though; I'm 
> currently trying to track down a nasty synchronization bug in the threading.
> 
> To make this feature work, we'd probably have to do something like this:
> 
> - Add a timeout property to HttpMethod or HttpMethodBase
> - Just before executing a method, set an internal "endTime" property
> - Every time we're about to do a socket operation, e.g. in 
> AutoCloseInputStream.read(), compare the current time and endTime.  If 
> we're past endTime, though an exception.  If not, adjust the socket 
> timeout so that the read operation can't go past endTime.
> - Do similar things while waiting on the connection pool, opening 
> sockets, etc.
> 
> Yuck.  I keep thinking there *must* be a simpler way, but I haven't 
> found it yet.
> 
> -- Laura
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


Mime
View raw message