ChrisHegarty opened a new issue, #15317:
URL: https://github.com/apache/lucene/issues/15317
Potential hang with initialisation of `TermsEnum` and `BaseTermsEnum`.
The static `TermsEnum.EMPTY` initialises to an implementation of
`BaseTermsEnum`. `TermsEnum` is a superclass of `BaseTermsEnum`, so there is a
clear dependency between these classes. If a subclass of `BaseTermsEnum` is
initialising it may grab the lock on `BaseTermsEnum`, and prevent `TermsEnum`
from initialising. E.g.
```
"main" #3 [8963] prio=5 os_prio=31 cpu=30.57ms elapsed=2.19s
tid=0x0000000123815a00 nid=8963 in Object.wait() [0x000000016b24e000]
java.lang.Thread.State: RUNNABLE
at TermsEnumClinitHang.main(TermsEnumClinitHang.java:22)
- waiting on the Class initialization monitor for
org.apache.lucene.index.TermsEnum
"TEST_THREAD" #25 [27395] prio=5 os_prio=31 cpu=1.54ms elapsed=2.17s
tid=0x000000012382e800 nid=27395 in Object.wait() [0x000000016d632000]
java.lang.Thread.State: RUNNABLE
at org.apache.lucene.index.TermsEnum.<clinit>(TermsEnum.java:199)
- waiting on the Class initialization monitor for
org.apache.lucene.index.BaseTermsEnum
at TermsEnumClinitHang$1.run(TermsEnumClinitHang.java:15)
...
```
```
import org.apache.lucene.index.BaseTermsEnum;
import org.apache.lucene.index.ImpactsEnum;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.BytesRef;
public class TermsEnumClinitHang {
public static void main(String... args) throws Exception {
Thread t = new Thread() {
public void run() {
System.out.println("Test thread about to access TermsEnum.EMPTY");
// This will block until the main thread completes static
initialization of MyBaseTermsEnum
var empty = TermsEnum.EMPTY;
System.out.println("Test thread done - empty=" + empty);
}
};
t.setName("TEST_THREAD");
t.start();
var myBaseTermsEnum = new MyBaseTermsEnum();
System.out.println("Test thread done - myBaseTermsEnum=" +
myBaseTermsEnum);
}
static class MyBaseTermsEnum extends BaseTermsEnum {
@Override public SeekStatus seekCeil(BytesRef text) { return null; }
@Override public void seekExact(long ord) { }
@Override public BytesRef term() { return null; }
@Override public long ord() { return 0; }
@Override public int docFreq() { return 0;}
@Override public long totalTermFreq() { return 0;}
@Override public PostingsEnum postings(PostingsEnum reuse, int flags) {
return null; }
@Override public ImpactsEnum impacts(int flags) { return null; }
@Override public BytesRef next() { return null; }
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]