LUCENE-9084: fix potential deadlock due to circular synchronization in AnalyzingInfixSuggester

This commit is contained in:
Mike McCandless 2020-01-08 19:28:36 -05:00
parent 08b64aab8f
commit deba7d1404
2 changed files with 12 additions and 10 deletions

View File

@ -120,7 +120,8 @@ Optimizations
Bug Fixes
---------------------
(No changes)
* LUCENE-9084: Fix potential deadlock due to circular synchronization in AnalyzingInfixSuggester (Paul Ward)
Other
---------------------

View File

@ -368,15 +368,16 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
};
}
private synchronized void ensureOpen() throws IOException {
if (writer == null) {
if (DirectoryReader.indexExists(dir)) {
// Already built; open it:
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.APPEND));
} else {
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.CREATE));
}
synchronized (searcherMgrLock) {
private void ensureOpen() throws IOException {
synchronized (searcherMgrLock) {
if (writer == null) {
if (DirectoryReader.indexExists(dir)) {
// Already built; open it:
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.APPEND));
} else {
writer = new IndexWriter(dir, getIndexWriterConfig(getGramAnalyzer(), IndexWriterConfig.OpenMode.CREATE));
}
SearcherManager oldSearcherMgr = searcherMgr;
searcherMgr = new SearcherManager(writer, null);
if (oldSearcherMgr != null) {