Closing the DirTaxonomyReader while another thread access the cache can throw NPE [LUCENE-10077]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
When we close a `DirectoryTaxonomyReader` in `doClose`, we set the `categoryCache` to null. But if a thread is next after this `doClose` call, it will still try to acquire a lock and `synchronize` on it. This will result in an NPE.
This works well today, because we operate on the assumption that the user will always call `doClose` after all threads have completed.
One suggestion by @mikemccand in this [PR](https://github.com/apache/lucene/pull/179#discussion_r697880516) was to make categoryCache final and throw an AlreadyClosedException.
---
Migrated from [LUCENE-10077](https://issues.apache.org/jira/browse/LUCENE-10077) by Gautam Worah (@gautamworah96), updated Sep 01 2021
Contributor guide
Research direction
Start at DirectoryTaxonomyReader#doClose and trace how categoryCache is accessed during close. Reproduce or cover the concurrent access case, then verify that a reader closed during cache access no longer throws an unexpected NullPointerException and instead follows the intended closed-reader behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100