JDK-6871697 : LinkedBlockingQueue Iterator/remove/poll race
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-08-13
  • Updated: 2011-04-06
  • Resolved: 2009-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u17-revFixed 7 b72Fixed
Related Reports
Relates :  
Relates :  
Description
Rarely, OfferRemoveLoops.java fails as in the jtr file below:

--------------------------------------------------
TEST: java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java
JDK under test: (/usr/local/google/home/martin/ws/upstream/build/linux-amd64)
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-martinrb_2009_07_11_16_08-b00)
OpenJDK 64-Bit Server VM (build 16.0-b07, mixed mode)

ACTION: build -- Passed. Build successful
REASON: Named class compiled on demand
TIME:   0.94 seconds
messages:
command: build OfferRemoveLoops
reason: Named class compiled on demand
elapsed time (seconds): 0.94

ACTION: compile -- Passed. Compilation successful
REASON: .class file out of date or does not exist
TIME:   0.937 seconds
messages:
command: compile
/usr/local/google/home/martin/ws/upstream/test/java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java
reason: .class file out of date or does not exist
elapsed time (seconds): 0.937
STDOUT:
STDERR:

ACTION: main -- Failed. Execution failed: `main' threw exception:
java.lang.AssertionError: Some tests failed
REASON: User specified action: run main OfferRemoveLoops 300
TIME:   22.964 seconds
messages:
command: main OfferRemoveLoops300
reason: User specified action: run main OfferRemoveLoops 300
elapsed time (seconds): 22.964
STDOUT:
LinkedBlockingQueue
LinkedBlockingQueue
LinkedBlockingDeque
LinkedBlockingDeque
ArrayBlockingQueue
PriorityBlockingQueue
ConcurrentLinkedQueue
LinkedTransferQueue

Passed = 5322725, failed = 4

STDERR:
Hung thread: offerer
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:867)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1197)
java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:214)
java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:290)
java.util.concurrent.LinkedBlockingQueue.offer(LinkedBlockingQueue.java:415)
OfferRemoveLoops$1.realRun(OfferRemoveLoops.java:99)
OfferRemoveLoops$1CheckedThread.run(OfferRemoveLoops.java:89)
java.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:813)
	at OfferRemoveLoops.testQueue(OfferRemoveLoops.java:149)
	at OfferRemoveLoops.test(OfferRemoveLoops.java:53)
	at OfferRemoveLoops.instanceMain(OfferRemoveLoops.java:168)
	at OfferRemoveLoops.main(OfferRemoveLoops.java:166)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:96)
	at java.lang.Thread.run(Thread.java:717)
Hung thread: scanner
java.util.concurrent.LinkedBlockingQueue$Itr.nextNode(LinkedBlockingQueue.java:780)
java.util.concurrent.LinkedBlockingQueue$Itr.next(LinkedBlockingQueue.java:791)
OfferRemoveLoops.checkNotContainsNull(OfferRemoveLoops.java:47)
OfferRemoveLoops$3.realRun(OfferRemoveLoops.java:132)
OfferRemoveLoops$1CheckedThread.run(OfferRemoveLoops.java:89)
java.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:813)
	at OfferRemoveLoops.testQueue(OfferRemoveLoops.java:149)
	at OfferRemoveLoops.test(OfferRemoveLoops.java:53)
	at OfferRemoveLoops.instanceMain(OfferRemoveLoops.java:168)
	at OfferRemoveLoops.main(OfferRemoveLoops.java:166)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:96)
	at java.lang.Thread.run(Thread.java:717)
java.lang.AssertionError: Some tests failed
	at OfferRemoveLoops.instanceMain(OfferRemoveLoops.java:170)
	at OfferRemoveLoops.main(OfferRemoveLoops.java:166)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:96)
	at java.lang.Thread.run(Thread.java:717)

Comments
EVALUATION changeset for this fix: http://hg.openjdk.java.net/jdk7/tl/jdk/rev/69396f593772
27-08-2009

EVALUATION There's a rare race in LBQ.Itr.nextNode if - iterator is visiting Node p - p is removed via remove(Object) - p's successor is dequeued - iterator tries to advance - infloop! http://cr.openjdk.java.net/~martin/webrevs/openjdk7/LBQIteratorRace/
13-08-2009