Opened 5 years ago

Closed 5 years ago

#16679 closed defect (fixed)

Troubleshoot DrawActionTest.testTicket12011

Reported by: Don-vip Owned by: team
Priority: normal Milestone: 18.09
Component: Unit tests Version:
Keywords: deadlock Cc: ris, michael2402, floscher, wiktorn, simon04, stoecker


For quite some time we have an unstable test:


It fails quite often, more often when the server is stressed. The fact that the error is a timeout makes me think we have a race condition leading to a deadlock.

Any help welcome to diagnose the error as I can't find enough time to do it.

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by wiktorn

I took a look at it. Relevant thread dump:

"AWT-EventQueue-0" #147 prio=6 os_prio=0 tid=0x00007fe56c073800 nid=0xc5a waiting on condition [0x00007fe576fc0000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000ec253bd8> (a java.util.concurrent.locks.ReentrantReadWriteLock$NonfairSync)
        at java.util.concurrent.locks.LockSupport.park(
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(
        at java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.lock(
        at org.openstreetmap.josm.actions.mapmode.DrawAction.redrawIfRequired(
        at org.openstreetmap.josm.actions.mapmode.DrawAction.addHighlighting(
        at org.openstreetmap.josm.actions.mapmode.DrawAction.lambda$selectionChanged$4(
        at org.openstreetmap.josm.actions.mapmode.DrawAction$$Lambda$436/ Source)
        at java.awt.event.InvocationEvent.dispatch(
        at java.awt.EventQueue.dispatchEventImpl(
        at java.awt.EventQueue.access$500(
        at java.awt.EventQueue$
        at java.awt.EventQueue$
        at Method)
        at java.awt.EventQueue.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForFilters(
        at java.awt.EventDispatchThread.pumpEventsForFilter(
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(
        at java.awt.EventDispatchThread.pumpEvents(
        at java.awt.EventDispatchThread.pumpEvents(

"main" #1 prio=5 os_prio=0 tid=0x00007fe60400e800 nid=0xbc4 in Object.wait() [0x00007fe60b152000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(
        at java.awt.EventQueue.invokeAndWait(
        - locked <0x00000000ec311f48> (a java.awt.EventQueue$1AWTInvocationLock)
        at java.awt.EventQueue.invokeAndWait(
        at javax.swing.SwingUtilities.invokeAndWait(
        at org.openstreetmap.josm.gui.util.GuiHelper.runInEDTAndWaitWithException(
        at$$Lambda$137/ Source)
        - locked <0x00000000ec253c38> (a java.lang.Object)
        at org.openstreetmap.josm.command.AddCommand.undoCommand(
        at org.openstreetmap.josm.command.SequenceCommand.undoCommands(
        at org.openstreetmap.josm.command.SequenceCommand.undoCommand(
        - locked <0x00000000c25191d8> (a
        at org.openstreetmap.josm.actions.mapmode.DrawActionTest.testTicket12011(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(
        at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.executeTestMethod(
        at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.invokeExplosively(
        at mockit.integration.junit4.internal.FakeFrameworkMethod.invokeExplosively(
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(
        at org.openstreetmap.josm.testutils.JOSMTestRules$CreateJosmEnvironment.evaluate(
        at org.junit.rules.RunRules.evaluate(
        at org.junit.runners.ParentRunner.runLeaf(
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(
        at org.junit.runners.ParentRunner$
        at org.junit.runners.ParentRunner$1.schedule(
        at org.junit.runners.ParentRunner.runChildren(
        at org.junit.runners.ParentRunner.access$000(
        at org.junit.runners.ParentRunner$2.evaluate(

Monitor addresses doesn't match, but looking at the code, it looks like we have following code in UndoRedoHandler:

    public synchronized void undo(int num) {

We acquire DataSet write lock in UndoRedoHandler in main thread and runInEDTAndWaits to process selectionChangedEvents. And in DrawAction.selectionChanged we try to require lock on DataSet because we change highligted element.

First solution that comes to my mind is to move whole UndoRedoHandler.undo to EDT thread so the locking will occur within the same thread and problem will not occur.

I'm not sure what kind of race we have here, that the code takes different path. I guess that it might be connected with which primitve gets highlighted or something.

comment:2 in reply to:  1 Changed 5 years ago by Don-vip

Replying to wiktorn:

I took a look at it.


First solution that comes to my mind is to move whole UndoRedoHandler.undo to EDT thread so the locking will occur within the same thread and problem will not occur.

No better idea, I think we can give it a try.

comment:3 Changed 5 years ago by Don-vip

Milestone: 18.09

comment:4 Changed 5 years ago by wiktorn

Resolution: fixed
Status: newclosed

In 14204/josm:

Move undo handler to EDT

To prevent live-locks when undo is called outside EDT and locks DataSet, and
DrawAction.selectionChanged tries to reaquire this lock in EDT thread.

Also - add synchronized keyword to redo and clean, to be symetrical with undo.

Closes: #16679

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.