You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by James Shaw <js...@zepler.net> on 2013/01/30 12:22:35 UTC

Interrupt flag getting cleared

I'm having some trouble tracking this down, but I believe that
httpclient 4.2.3 is clearing the interrupt flag.

My code looks like this:

executorService.submit(new Runnable() {
    @Override public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            consume(); // calls AWS SDK which uses Apache HttpClient
        }
    }
});

Sometimes this loop does not terminate when calling
Future.cancel(true).  The only piece of diagnostics I have so far is
this:
Exception 'java.lang.InterruptedException' occurred in thread
'queue-consumer-reader-thread-1' at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
Exception 'java.lang.InterruptedException' occurred in thread
'queue-consumer-reader-thread-1' at
org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
Exception 'java.lang.InterruptedException' occurred in thread
'queue-consumer-reader-thread-1' at
org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
Exception 'java.lang.InterruptedException' occurred in thread
'queue-consumer-reader-thread-1' at
org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)

Should I not expect the interrupt flag to be preserved?  Do you have
any suggestions how I could isolate this bug (I'm not 100% sure if
it's in HttpClient or AWS client right now)?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by James Shaw <js...@zepler.net>.
On 30 January 2013 13:00, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2013-01-30 at 12:28 +0000, James Shaw wrote:
>> On 30 January 2013 12:26, Oleg Kalnichevski <ol...@apache.org> wrote:
>> > On Wed, 2013-01-30 at 12:07 +0000, James Shaw wrote:
>> >> On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
>> >> > On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
>> >> >> I'm having some trouble tracking this down, but I believe that
>> >> >> httpclient 4.2.3 is clearing the interrupt flag.
>> >> >>
>> >> >> My code looks like this:
>> >> >>
>> >> >> executorService.submit(new Runnable() {
>> >> >>     @Override public void run() {
>> >> >>         while (!Thread.currentThread().isInterrupted()) {
>> >> >>             consume(); // calls AWS SDK which uses Apache HttpClient
>> >> >>         }
>> >> >>     }
>> >> >> });
>> >> >>
>> >> >> Sometimes this loop does not terminate when calling
>> >> >> Future.cancel(true).  The only piece of diagnostics I have so far is
>> >> >> this:
>> >> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> >> 'queue-consumer-reader-thread-1' at
>> >> >> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
>> >> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> >> 'queue-consumer-reader-thread-1' at
>> >> >> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
>> >> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> >> 'queue-consumer-reader-thread-1' at
>> >> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
>> >> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> >> 'queue-consumer-reader-thread-1' at
>> >> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
>> >> >>
>> >> >> Should I not expect the interrupt flag to be preserved?  Do you have
>> >> >> any suggestions how I could isolate this bug (I'm not 100% sure if
>> >> >> it's in HttpClient or AWS client right now)?
>> >> >>
>> >> >> Thanks
>> >> >>
>> >> >
>> >> > I am not aware of any place in HttpClient where it might meddle with the
>> >> > interrupt flag.
>> >> Is there anywhere that InterruptException is caught and either not
>> >> rethrown, or the flag is not explicitly set again?  That would be
>> >> sufficient.
>> >>
>> >
>> > There are two places where InterruptedException is re-thrown as
>> > InterruptedIOException. I am not aware of any place where
>> > InterruptedException can be caught and not re-thrown.
>> >
>> But by rethrowing a different exception, the interrupt flag will be cleared, no?
>>
>
> I believe so. Honestly, I just do not know what the correct behavior
> should be. It does appear, though, it is usually expected that a well
> behaved application would re-interrupt the thread if it does not
> propagate the InterruptedException [1]
Yes, that's the behaviour my code is relying on.

>
> Please raise a JIRA for this defect.
Raised https://issues.apache.org/jira/browse/HTTPCLIENT-1311.  Thanks
for your help, Oleg!

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-01-30 at 12:28 +0000, James Shaw wrote:
> On 30 January 2013 12:26, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Wed, 2013-01-30 at 12:07 +0000, James Shaw wrote:
> >> On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
> >> > On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
> >> >> I'm having some trouble tracking this down, but I believe that
> >> >> httpclient 4.2.3 is clearing the interrupt flag.
> >> >>
> >> >> My code looks like this:
> >> >>
> >> >> executorService.submit(new Runnable() {
> >> >>     @Override public void run() {
> >> >>         while (!Thread.currentThread().isInterrupted()) {
> >> >>             consume(); // calls AWS SDK which uses Apache HttpClient
> >> >>         }
> >> >>     }
> >> >> });
> >> >>
> >> >> Sometimes this loop does not terminate when calling
> >> >> Future.cancel(true).  The only piece of diagnostics I have so far is
> >> >> this:
> >> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> >> 'queue-consumer-reader-thread-1' at
> >> >> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
> >> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> >> 'queue-consumer-reader-thread-1' at
> >> >> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
> >> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> >> 'queue-consumer-reader-thread-1' at
> >> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
> >> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> >> 'queue-consumer-reader-thread-1' at
> >> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
> >> >>
> >> >> Should I not expect the interrupt flag to be preserved?  Do you have
> >> >> any suggestions how I could isolate this bug (I'm not 100% sure if
> >> >> it's in HttpClient or AWS client right now)?
> >> >>
> >> >> Thanks
> >> >>
> >> >
> >> > I am not aware of any place in HttpClient where it might meddle with the
> >> > interrupt flag.
> >> Is there anywhere that InterruptException is caught and either not
> >> rethrown, or the flag is not explicitly set again?  That would be
> >> sufficient.
> >>
> >
> > There are two places where InterruptedException is re-thrown as
> > InterruptedIOException. I am not aware of any place where
> > InterruptedException can be caught and not re-thrown.
> >
> But by rethrowing a different exception, the interrupt flag will be cleared, no?
> 

I believe so. Honestly, I just do not know what the correct behavior
should be. It does appear, though, it is usually expected that a well
behaved application would re-interrupt the thread if it does not
propagate the InterruptedException [1]

Please raise a JIRA for this defect.

Oleg

[1] http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html





---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by James Shaw <js...@zepler.net>.
On 30 January 2013 12:26, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2013-01-30 at 12:07 +0000, James Shaw wrote:
>> On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
>> > On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
>> >> I'm having some trouble tracking this down, but I believe that
>> >> httpclient 4.2.3 is clearing the interrupt flag.
>> >>
>> >> My code looks like this:
>> >>
>> >> executorService.submit(new Runnable() {
>> >>     @Override public void run() {
>> >>         while (!Thread.currentThread().isInterrupted()) {
>> >>             consume(); // calls AWS SDK which uses Apache HttpClient
>> >>         }
>> >>     }
>> >> });
>> >>
>> >> Sometimes this loop does not terminate when calling
>> >> Future.cancel(true).  The only piece of diagnostics I have so far is
>> >> this:
>> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> 'queue-consumer-reader-thread-1' at
>> >> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
>> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> 'queue-consumer-reader-thread-1' at
>> >> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
>> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> 'queue-consumer-reader-thread-1' at
>> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
>> >> Exception 'java.lang.InterruptedException' occurred in thread
>> >> 'queue-consumer-reader-thread-1' at
>> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
>> >>
>> >> Should I not expect the interrupt flag to be preserved?  Do you have
>> >> any suggestions how I could isolate this bug (I'm not 100% sure if
>> >> it's in HttpClient or AWS client right now)?
>> >>
>> >> Thanks
>> >>
>> >
>> > I am not aware of any place in HttpClient where it might meddle with the
>> > interrupt flag.
>> Is there anywhere that InterruptException is caught and either not
>> rethrown, or the flag is not explicitly set again?  That would be
>> sufficient.
>>
>
> There are two places where InterruptedException is re-thrown as
> InterruptedIOException. I am not aware of any place where
> InterruptedException can be caught and not re-thrown.
>
But by rethrowing a different exception, the interrupt flag will be cleared, no?

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-01-30 at 12:07 +0000, James Shaw wrote:
> On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
> > On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
> >> I'm having some trouble tracking this down, but I believe that
> >> httpclient 4.2.3 is clearing the interrupt flag.
> >>
> >> My code looks like this:
> >>
> >> executorService.submit(new Runnable() {
> >>     @Override public void run() {
> >>         while (!Thread.currentThread().isInterrupted()) {
> >>             consume(); // calls AWS SDK which uses Apache HttpClient
> >>         }
> >>     }
> >> });
> >>
> >> Sometimes this loop does not terminate when calling
> >> Future.cancel(true).  The only piece of diagnostics I have so far is
> >> this:
> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> 'queue-consumer-reader-thread-1' at
> >> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> 'queue-consumer-reader-thread-1' at
> >> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> 'queue-consumer-reader-thread-1' at
> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
> >> Exception 'java.lang.InterruptedException' occurred in thread
> >> 'queue-consumer-reader-thread-1' at
> >> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
> >>
> >> Should I not expect the interrupt flag to be preserved?  Do you have
> >> any suggestions how I could isolate this bug (I'm not 100% sure if
> >> it's in HttpClient or AWS client right now)?
> >>
> >> Thanks
> >>
> >
> > I am not aware of any place in HttpClient where it might meddle with the
> > interrupt flag.
> Is there anywhere that InterruptException is caught and either not
> rethrown, or the flag is not explicitly set again?  That would be
> sufficient.
> 

There are two places where InterruptedException is re-thrown as
InterruptedIOException. I am not aware of any place where
InterruptedException can be caught and not re-thrown.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by James Shaw <js...@zepler.net>.
On 30 January 2013 12:07, James Shaw <js...@zepler.net> wrote:
> On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
>> On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
>>> I'm having some trouble tracking this down, but I believe that
>>> httpclient 4.2.3 is clearing the interrupt flag.
>>>
>>> My code looks like this:
>>>
>>> executorService.submit(new Runnable() {
>>>     @Override public void run() {
>>>         while (!Thread.currentThread().isInterrupted()) {
>>>             consume(); // calls AWS SDK which uses Apache HttpClient
>>>         }
>>>     }
>>> });
>>>
>>> Sometimes this loop does not terminate when calling
>>> Future.cancel(true).  The only piece of diagnostics I have so far is
>>> this:
>>> Exception 'java.lang.InterruptedException' occurred in thread
>>> 'queue-consumer-reader-thread-1' at
>>> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
>>> Exception 'java.lang.InterruptedException' occurred in thread
>>> 'queue-consumer-reader-thread-1' at
>>> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
>>> Exception 'java.lang.InterruptedException' occurred in thread
>>> 'queue-consumer-reader-thread-1' at
>>> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
>>> Exception 'java.lang.InterruptedException' occurred in thread
>>> 'queue-consumer-reader-thread-1' at
>>> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
>>>
>>> Should I not expect the interrupt flag to be preserved?  Do you have
>>> any suggestions how I could isolate this bug (I'm not 100% sure if
>>> it's in HttpClient or AWS client right now)?
>>>
>>> Thanks
>>>
>>
>> I am not aware of any place in HttpClient where it might meddle with the
>> interrupt flag.
> Is there anywhere that InterruptException is caught and either not
> rethrown, or the flag is not explicitly set again?  That would be
> sufficient.
Such as this, perhaps (I found this one while debugging):

try {
    managedConn = connRequest.getConnection(timeout, TimeUnit.MILLISECONDS);
} catch(InterruptedException interrupted) {
    InterruptedIOException iox = new InterruptedIOException();
    iox.initCause(interrupted);
    throw iox;
}
>From https://svn.apache.org/repos/asf/httpcomponents/httpclient/tags/4.2.3/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by James Shaw <js...@zepler.net>.
On 30 January 2013 11:54, Oleg Kalnichevski <ol...@apache.org> wrote:
> On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
>> I'm having some trouble tracking this down, but I believe that
>> httpclient 4.2.3 is clearing the interrupt flag.
>>
>> My code looks like this:
>>
>> executorService.submit(new Runnable() {
>>     @Override public void run() {
>>         while (!Thread.currentThread().isInterrupted()) {
>>             consume(); // calls AWS SDK which uses Apache HttpClient
>>         }
>>     }
>> });
>>
>> Sometimes this loop does not terminate when calling
>> Future.cancel(true).  The only piece of diagnostics I have so far is
>> this:
>> Exception 'java.lang.InterruptedException' occurred in thread
>> 'queue-consumer-reader-thread-1' at
>> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
>> Exception 'java.lang.InterruptedException' occurred in thread
>> 'queue-consumer-reader-thread-1' at
>> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
>> Exception 'java.lang.InterruptedException' occurred in thread
>> 'queue-consumer-reader-thread-1' at
>> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
>> Exception 'java.lang.InterruptedException' occurred in thread
>> 'queue-consumer-reader-thread-1' at
>> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
>>
>> Should I not expect the interrupt flag to be preserved?  Do you have
>> any suggestions how I could isolate this bug (I'm not 100% sure if
>> it's in HttpClient or AWS client right now)?
>>
>> Thanks
>>
>
> I am not aware of any place in HttpClient where it might meddle with the
> interrupt flag.
Is there anywhere that InterruptException is caught and either not
rethrown, or the flag is not explicitly set again?  That would be
sufficient.

> In any case I would recommend using
> PoolingClientConnectionManager instead of the deprecated
> ThreadSafeClientConnManager. If the problem still persists after
> removing all references to deprecated code, the problem is more likely
> to be caused by the AWS code.
>
I don't think I can since the AWS client creates the connection
manager itself and offers no API for providing my own *sigh*.  I've
raised a ticket with AWS so we'll see what they have to say.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Interrupt flag getting cleared

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-01-30 at 11:22 +0000, James Shaw wrote:
> I'm having some trouble tracking this down, but I believe that
> httpclient 4.2.3 is clearing the interrupt flag.
> 
> My code looks like this:
> 
> executorService.submit(new Runnable() {
>     @Override public void run() {
>         while (!Thread.currentThread().isInterrupted()) {
>             consume(); // calls AWS SDK which uses Apache HttpClient
>         }
>     }
> });
> 
> Sometimes this loop does not terminate when calling
> Future.cancel(true).  The only piece of diagnostics I have so far is
> this:
> Exception 'java.lang.InterruptedException' occurred in thread
> 'queue-consumer-reader-thread-1' at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
> Exception 'java.lang.InterruptedException' occurred in thread
> 'queue-consumer-reader-thread-1' at
> org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:164)
> Exception 'java.lang.InterruptedException' occurred in thread
> 'queue-consumer-reader-thread-1' at
> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:410)
> Exception 'java.lang.InterruptedException' occurred in thread
> 'queue-consumer-reader-thread-1' at
> org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:423)
> 
> Should I not expect the interrupt flag to be preserved?  Do you have
> any suggestions how I could isolate this bug (I'm not 100% sure if
> it's in HttpClient or AWS client right now)?
> 
> Thanks
> 

I am not aware of any place in HttpClient where it might meddle with the
interrupt flag. In any case I would recommend using
PoolingClientConnectionManager instead of the deprecated
ThreadSafeClientConnManager. If the problem still persists after
removing all references to deprecated code, the problem is more likely
to be caused by the AWS code.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org