Return reader only if pool not closed#2074
Merged
petebankhead merged 1 commit intoqupath:mainfrom Jan 20, 2026
Merged
Conversation
Member
|
I think this makes sense, so will merge and see how it behaves. Would it be worthwhile to synchronise any use of the |
Contributor
Author
In the scenario described above, that would prevent the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Attempt to fix #2052
The exception of the issue looks like this:
This
ConcurrentModificationExceptionoccurs while iterating onBioFormatsImageServer.ReaderPool.cleanablesin theclose()function:qupath/qupath-extension-bioformats/src/main/java/qupath/lib/images/servers/bioformats/BioFormatsImageServer.java
Lines 1638 to 1651 in 837d984
This means
cleanablesis modified somewhere else. The only possible place is inReaderPool.createReader():qupath/qupath-extension-bioformats/src/main/java/qupath/lib/images/servers/bioformats/BioFormatsImageServer.java
Lines 1424 to 1425 in 837d984
This means that the
BioFormatsImageServeris closed while a reader is being created. My theory is that this scenario occurs when:BioFormatsImageServerhas 5 actives readers, which are all being used at the moment, and can create up to 10 readers.BioFormatsImageServer.readTile(). Since all active readers are being used and it's possible to create a new reader, a request to create a new reader is made. This is done in a thread of the common pool:qupath/qupath-extension-bioformats/src/main/java/qupath/lib/images/servers/bioformats/BioFormatsImageServer.java
Line 1439 in 837d984
BioFormatsImageServer.BioFormatsImageServeris being closed, the new reader of above finishes being created. A new cleanable is added:qupath/qupath-extension-bioformats/src/main/java/qupath/lib/images/servers/bioformats/BioFormatsImageServer.java
Lines 1424 to 1425 in 837d984
This triggers the
ConcurrentModificationException.This scenario is quite unlikely, which is why #2052 rarely happens. This PR attempt to fixes that by checking if the
BioFormatsImageServeris closed before adding a newcleanable.This doesn't totally fixes the issue (the
ConcurrentModificationExceptioncould still happen), but it should now be very unlikely. I run the unit tests around 200 times with the GitHub actions, and the issue never happened again.