imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
16 stars 25 forks source link

Building locally hangs on Windows #305

Closed hinerm closed 1 month ago

hinerm commented 1 month ago

I ran into two scenarios where the tests hang (building with mvn clean install on the command line):

hinerm commented 1 month ago

Note: this happens with Java 8.

Will test with pom-scijava 38 to see if that helps

hinerm commented 1 month ago

pom-scijava 38.0.1 did not fix things

I just dug into the threads and think I found the source of the deadlock. In thread main we dispose the Context which calls doDispose which is synchronized:

image

Then on the EDT when ij.ImageJ is closed (via its run method) it calls its dispose method which we have a hook in to dispose our Context: image

Which, of course, it cannot do because main has a lock on the Context.

This seems like an infinite loop since whenever the Context is disposed it will lead to the LegacyService disposing, which will cause ij.ImageJ to dispose, which will cause the Context to dispose, which etc, etc...

This is 🤯 to me but my first thought is that if ImageJ shuts down first then its disposing flag is true and this line short-circuits and no infinite loop.

I'm wondering if this test is insufficient and missing the case where we shut down from the Context first...

hinerm commented 1 month ago

I'm wondering if this test is insufficient and missing the case where we shut down from the Context first...

On the main thread, the helper is EideticIJ1Helper@5886, with the disposing state set appropriately, but on the EDT the helper is IJ1Helper@7470 that doesn't know it's disposing. Can't have that...