hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Potapov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPASYNC-56) Deadlock in DefaultClientExchangeHandlerImpl.start()
Date Fri, 11 Oct 2013 08:14:44 GMT

    [ https://issues.apache.org/jira/browse/HTTPASYNC-56?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13792449#comment-13792449
] 

Dmitry Potapov commented on HTTPASYNC-56:
-----------------------------------------

Here the piece of javacore.txt gerenated by JVM:
{noformat}
3XMTHREADINFO      "Thread A" J9VMThread:0x00000000027E0200, j9thread_t:0x00007FC3E9C28770,
java/lang/Thread:0x00000000144528A0, state:B, prio=5
3XMJAVALTHREAD            (java/lang/Thread getId:0x1AE, isDaemon:false)
3XMTHREADINFO1            (native thread ID:0x4772, native priority:0x5, native policy:UNKNOWN)
3XMTHREADINFO2            (native stack address range from:0x00007FC398004000, to:0x00007FC398045000,
size:0x41000)
3XMTHREADBLOCK     Blocked on: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x000000027AD591B0
Owned by: "Thread B" (J9VMThread:0x000000000369E600, java/lang/Thread:0x00000000161F38E0)
3XMHEAPALLOC             Heap bytes allocated since last GC cycle=0 (0x0)
3XMTHREADINFO3           Java callstack:
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.connectionAllocated(DefaultClientExchangeHandlerImpl.java:266(Compiled
Code))
5XESTACKTRACE                   (entered lock: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x000000027AD591B0,
entry count: 1)
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.access$000(DefaultClientExchangeHandlerImpl.java:57(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl$1.completed(DefaultClientExchangeHandlerImpl.java:333(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl$1.completed(DefaultClientExchangeHandlerImpl.java:340(Compiled
Code))
4XESTACKTRACE                at org/apache/http/concurrent/BasicFuture.completed(BasicFuture.java:115(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.completed(PoolingNHttpClientConnectionManager.java:439(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.completed(PoolingNHttpClientConnectionManager.java:423(Compiled
Code))
4XESTACKTRACE                at org/apache/http/concurrent/BasicFuture.completed(BasicFuture.java:115(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:443(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.lease(AbstractNIOConnPool.java:276(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.lease(AbstractNIOConnPool.java:248(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:239(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.requestConnection(DefaultClientExchangeHandlerImpl.java:326(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:120(Compiled
Code))
5XESTACKTRACE                   (entered lock: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x0000000311DD8EA0,
entry count: 1)
4XESTACKTRACE                at org/apache/http/impl/nio/client/InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:188(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:63(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:93(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:78(Compiled
Code))
...
3XMTHREADINFO      "Thread B" J9VMThread:0x000000000369E600, j9thread_t:0x00007FC3EA6100B0,
java/lang/Thread:0x00000000161F38E0, state:B, prio=5
3XMJAVALTHREAD            (java/lang/Thread getId:0x486, isDaemon:false)
3XMTHREADINFO1            (native thread ID:0x4A4A, native priority:0x5, native policy:UNKNOWN)
3XMTHREADINFO2            (native stack address range from:0x00007FC2FC65D000, to:0x00007FC2FC69E000,
size:0x41000)
3XMTHREADBLOCK     Blocked on: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x0000000311DD8EA0
Owned by: "Thread A" (J9VMThread:0x00000000027E0200, java/lang/Thread:0x00000000144528A0)
3XMHEAPALLOC             Heap bytes allocated since last GC cycle=0 (0x0)
3XMTHREADINFO3           Java callstack:
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.connectionAllocated(DefaultClientExchangeHandlerImpl.java:266(Compiled
Code))
5XESTACKTRACE                   (entered lock: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x0000000311DD8EA0,
entry count: 1)
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.access$000(DefaultClientExchangeHandlerImpl.java:57(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl$1.completed(DefaultClientExchangeHandlerImpl.java:333(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl$1.completed(DefaultClientExchangeHandlerImpl.java:340(Compiled
Code))
4XESTACKTRACE                at org/apache/http/concurrent/BasicFuture.completed(BasicFuture.java:115(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.completed(PoolingNHttpClientConnectionManager.java:439(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.completed(PoolingNHttpClientConnectionManager.java:423(Compiled
Code))
4XESTACKTRACE                at org/apache/http/concurrent/BasicFuture.completed(BasicFuture.java:115(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.fireCallbacks(AbstractNIOConnPool.java:443(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.lease(AbstractNIOConnPool.java:276(Compiled
Code))
4XESTACKTRACE                at org/apache/http/nio/pool/AbstractNIOConnPool.lease(AbstractNIOConnPool.java:248(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:239(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.requestConnection(DefaultClientExchangeHandlerImpl.java:326(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:120(Compiled
Code))
5XESTACKTRACE                   (entered lock: org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl@0x000000027AD591B0,
entry count: 1)
4XESTACKTRACE                at org/apache/http/impl/nio/client/InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:188(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:63(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:93(Compiled
Code))
4XESTACKTRACE                at org/apache/http/impl/nio/client/CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:78(Compiled
Code))
{noformat}

> Deadlock in DefaultClientExchangeHandlerImpl.start()
> ----------------------------------------------------
>
>                 Key: HTTPASYNC-56
>                 URL: https://issues.apache.org/jira/browse/HTTPASYNC-56
>             Project: HttpComponents HttpAsyncClient
>          Issue Type: Bug
>    Affects Versions: 4.0-beta4
>            Reporter: Dmitry Potapov
>             Fix For: 4.0 Final
>
>
> How it looks like:
> 1. Theads A and B calls CloseableHttpAsyncClient.execute() of the same CloseableHttpAsyncClient
(problem may reproduce on two separate clients sharing single connection pool)
> 2. Each CloseableHttpAsyncClient.execute in turn calls InternalHttpAsyncClient.execute()
which creates DefaultClientExchangeHandlerImpl instance and calls DefaultClientExchangeHandlerImpl.start(),
which is synchronized
> 3. At this point, we have two DefaultClientExchangeHandlerImpl with locked monitors,
let these instances have names AH and BH.
> 4. DefaultClientExchangeHandlerImpl.start() calls requestConnection(), which in turn
calls PoolingNHttpClientConnectionManager.requestConnection()
> 5. At thread A: AbstractNIOConnPool.lease() adds completed request to the completedRequests
queue (line 271). This request callback has reference to the AH
> 6. At thread B: AbstractNIOConnPool.lease() adds completed request to the completedRequests
queue. This request callback has reference to BH
> 7. At thread B: AbstractNIOConnPool.fireCallbacks() is called. It polls AH from completedRequests
and calls AH callback, which tries to enter AH monitor and locks, because this monitor is
already locked.
> 8. At thread A: AbstractNIOConnPool.fireCallbacks() is called. It polls BH from completedRequests
(AH was polled at step 7) and calls BH callback, which tries to enter BH monitor and locks,
because this monitor is already locked.
> At this point we have threads A and B deadlocked.
> I have obvious solution for this particular dead-lock: make DefaultClientExchangeHandlerImpl.start()
not synchronized, because this object created only at single point, and .start() is called
immediately after construction.
> I'm not sure that there is no problems in other scenarious where .fireCallbacks() involved,
because DefaultClientExchangeHandlerImpl.requestConnection() may be called from other synchronized
methods.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

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


Mime
View raw message