powered by Jive Software

Smack instantShutdown/connect deadlock?

smack
android

#1

Hello Smack community,
I’ve been using Smack for some time now. I’ve recently started recycling connection objects instead of recreating them at every reconnection. Currently I’m using Smack 4.3.3, but the issues used to happen before since I started recycling connections.

I run on several threads and one thread might request instantShutdown() at any time, even while connect() is running. Consider the following thread stacktraces:

"XMPPConnector" prio=5 tid=25 Blocked
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x12d86c90 self=0x7ef3aff800
  | sysTid=22999 nice=0 cgrp=default sched=0/0 handle=0x7ef15f54f0
  | state=S schedstat=( 783958 0 1 ) utm=0 stm=0 core=6 HZ=100
  | stack=0x7ef14f3000-0x7ef14f5000 stackSize=1037KB
  | held mutexes=
  at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:-1)
  - waiting to lock <0x05c34a60> (a org.kontalk.client.KontalkConnection) held by thread 16
  at org.kontalk.service.XMPPConnectionHelper.connectOnce(XMPPConnectionHelper.java:192)
  at org.kontalk.service.XMPPConnectionHelper.connect(XMPPConnectionHelper.java:226)
  at org.kontalk.service.XMPPConnectionHelper.run(XMPPConnectionHelper.java:141)
"Thread-208" prio=5 tid=29 Blocked
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x12d91330 self=0x7ef184c800
  | sysTid=23005 nice=0 cgrp=default sched=0/0 handle=0x7eefbff4f0
  | state=S schedstat=( 819010 0 1 ) utm=0 stm=0 core=6 HZ=100
  | stack=0x7eefafd000-0x7eefaff000 stackSize=1037KB
  | held mutexes=
  at org.kontalk.client.smack.XMPPTCPConnection.instantShutdown(XMPPTCPConnection.java:-1)
  - waiting to lock <0x05c34a60> (a org.kontalk.client.KontalkConnection) held by thread 16
  at org.kontalk.service.XMPPConnectionHelper.shutdown(XMPPConnectionHelper.java:354)
  at org.kontalk.service.msgcenter.MessageCenterService$AbortThread.run(MessageCenterService.java:997)
"Smack Cached Executor" daemon prio=5 tid=16 Waiting
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x140c01c8 self=0x7ef3143600
  | sysTid=22992 nice=0 cgrp=default sched=0/0 handle=0x7ef39ff4f0
  | state=S schedstat=( 181057299 5351661 51 ) utm=17 stm=0 core=7 HZ=100
  | stack=0x7ef38fd000-0x7ef38ff000 stackSize=1037KB
  | held mutexes=
  at java.lang.Object.wait(Native method)
  - waiting on <0x075bea4f> (a java.lang.Object)
  at java.lang.Thread.parkFor$(Thread.java:2137)
  - locked <0x075bea4f> (a java.lang.Object)
  at sun.misc.Unsafe.park(Unsafe.java:358)
  at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:868)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(AbstractQueuedSynchronizer.java:993)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1307)
  at java.util.concurrent.Semaphore.acquireUninterruptibly(Semaphore.java:504)
  at org.kontalk.client.smack.XMPPTCPConnection$2.run(XMPPTCPConnection.java:1001)
  - locked <0x05c34a60> (a org.kontalk.client.KontalkConnection)
  at org.jivesoftware.smack.AsyncButOrdered$Handler.run(AsyncButOrdered.java:121)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
  at java.lang.Thread.run(Thread.java:764)
"Smack Writer (2)" daemon prio=5 tid=41 Blocked
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x13081aa0 self=0x7ef1847800
  | sysTid=22831 nice=0 cgrp=default sched=0/0 handle=0x7eedbd94f0
  | state=S schedstat=( 102058602 38992919 71 ) utm=6 stm=2 core=6 HZ=100
  | stack=0x7eedad7000-0x7eedad9000 stackSize=1037KB
  | held mutexes=
  at org.kontalk.client.smack.XMPPTCPConnection.notifyConnectionError(XMPPTCPConnection.java:-1)
  - waiting to lock <0x05c34a60> (a org.kontalk.client.KontalkConnection) held by thread 16
  at org.kontalk.client.smack.XMPPTCPConnection.access$4200(XMPPTCPConnection.java:154)
  at org.kontalk.client.smack.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1621)
  at org.kontalk.client.smack.XMPPTCPConnection$PacketWriter.access$4300(XMPPTCPConnection.java:1363)
  at org.kontalk.client.smack.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1412)
  at java.lang.Thread.run(Thread.java:764)
"Smack Scheduled Executor Service" daemon prio=5 tid=23 TimedWaiting
  | group="main" sCount=1 dsCount=0 flags=1 obj=0x13740e78 self=0x7ef347ba00
  | sysTid=16986 nice=0 cgrp=default sched=0/0 handle=0x7ef16fa4f0
  | state=S schedstat=( 37745570 1442604 50 ) utm=3 stm=0 core=7 HZ=100
  | stack=0x7ef15f8000-0x7ef15fa000 stackSize=1037KB
  | held mutexes=
  at java.lang.Object.wait(Native method)
  - waiting on <0x0df7aeb0> (a java.lang.Object)
  at java.lang.Thread.parkFor$(Thread.java:2137)
  - locked <0x0df7aeb0> (a java.lang.Object)
  at sun.misc.Unsafe.park(Unsafe.java:358)
  at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2101)
  at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1132)
  at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1113)
  at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1087)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1147)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
  at java.lang.Thread.run(Thread.java:764)

I can understand locking because of synchronized, but, if I understand those stacktraces right, how can this be possible?
It seems like some sort of deadlock… what am I doing wrong here?

I’d rather not remove the synchronized keywords from instantShutdown and connect.

Thanks


#2

Without an in-depth analysis, this is likely caused by a known bug in Smack 4.3.3 which has been fixed in the 4.3 branch with

If possible, please try a Smack 4.3.4-SNAPSHOT and report back if the still see the issue. Note that I plan to release Smack 4.3.4 within within the next few weeks.


#3

Thanks! I’ll try it as soon as possible.


#4

when is the 4.3.4 release ?I wait for you.