Apache Solr open-source search software
Fix for deadlock between indexing thread and parsing thread that occurs with long titles. Parsing thread waits for indexing thread to read from pipeIn, indexing thread waits for summary. This fixes bug #24301
Christoph Gollerdc4da65595d2
diff --git a/src/demo/org/apache/lucene/demo/html/HTMLParser.java b/src/demo/org/apache/lucene/demo/html/HTMLParser.javaindex e05fa0aab57..260e8cdba08 100644--- a/src/demo/org/apache/lucene/demo/html/HTMLParser.java+++ b/src/demo/org/apache/lucene/demo/html/HTMLParser.java@@ -20,8 +20,25 @@ public class HTMLParser implements HTMLParserConstants {boolean afterTag = false;boolean afterSpace = false;String eol = System.getProperty("line.separator");- PipedReader pipeIn = null;- PipedWriter pipeOut;+ Reader pipeIn = null;+ Writer pipeOut;+ private MyPipedInputStream pipeInStream = null;+ private PipedOutputStream pipeOutStream = null;++ private class MyPipedInputStream extends PipedInputStream{++ public MyPipedInputStream(){+ super();+ }++ public MyPipedInputStream(PipedOutputStream src) throws IOException{+ super(src);+ }++ public boolean full() throws IOException{+ return this.available() >= PipedInputStream.PIPE_SIZE;+ }+ }public HTMLParser(File file) throws FileNotFoundException {this(new FileInputStream(file));@@ -32,7 +49,7 @@ public class HTMLParser implements HTMLParserConstants {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (titleComplete || (length > SUMMARY_LENGTH))+ if (titleComplete || pipeInStream.full())break;wait(10);}@@ -46,7 +63,7 @@ InterruptedException {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (titleComplete || (length > SUMMARY_LENGTH))+ if (titleComplete || pipeInStream.full())break;wait(10);}@@ -60,7 +77,7 @@ InterruptedException {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (summary.length() >= SUMMARY_LENGTH)+ if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())break;wait(10);}@@ -70,16 +87,18 @@ InterruptedException {String sum = summary.toString().trim();String tit = getTitle();- if (sum.startsWith(tit))- return sum.substring(tit.length());+ if (sum.startsWith(tit) || sum.equals(""))+ return tit;elsereturn sum;}public Reader getReader() throws IOException {if (pipeIn == null) {- pipeIn = new PipedReader();- pipeOut = new PipedWriter(pipeIn);+ pipeInStream = new MyPipedInputStream();+ pipeOutStream = new PipedOutputStream(pipeInStream);+ pipeIn = new InputStreamReader(pipeInStream);+ pipeOut = new OutputStreamWriter(pipeOutStream);Thread thread = new ParserThread(this);thread.start(); // start parsing@@ -405,18 +424,18 @@ null)finally { jj_save(1, xla); }}- final private boolean jj_3_1() {- if (jj_scan_token(ArgQuote1)) return true;- if (jj_scan_token(CloseQuote1)) return true;- return false;- }-final private boolean jj_3_2() {if (jj_scan_token(ArgQuote2)) return true;if (jj_scan_token(CloseQuote2)) return true;return false;}+ final private boolean jj_3_1() {+ if (jj_scan_token(ArgQuote1)) return true;+ if (jj_scan_token(CloseQuote1)) return true;+ return false;+ }+public HTMLParserTokenManager token_source;SimpleCharStream jj_input_stream;public Token token, jj_nt;diff --git a/src/demo/org/apache/lucene/demo/html/HTMLParser.jj b/src/demo/org/apache/lucene/demo/html/HTMLParser.jjindex fb20fe23145..c0b7d5b6482 100644--- a/src/demo/org/apache/lucene/demo/html/HTMLParser.jj+++ b/src/demo/org/apache/lucene/demo/html/HTMLParser.jj@@ -84,8 +84,25 @@ public class HTMLParser {boolean afterTag = false;boolean afterSpace = false;String eol = System.getProperty("line.separator");- PipedReader pipeIn = null;- PipedWriter pipeOut;+ Reader pipeIn = null;+ Writer pipeOut;+ private MyPipedInputStream pipeInStream = null;+ private PipedOutputStream pipeOutStream = null;++ private class MyPipedInputStream extends PipedInputStream{++ public MyPipedInputStream(){+ super();+ }++ public MyPipedInputStream(PipedOutputStream src) throws IOException{+ super(src);+ }++ public boolean full() throws IOException{+ return this.available() >= PipedInputStream.PIPE_SIZE;+ }+ }public HTMLParser(File file) throws FileNotFoundException {this(new FileInputStream(file));@@ -96,7 +113,7 @@ public class HTMLParser {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (titleComplete || (length > SUMMARY_LENGTH))+ if (titleComplete || pipeInStream.full())break;wait(10);}@@ -110,7 +127,7 @@ InterruptedException {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (titleComplete || (length > SUMMARY_LENGTH))+ if (titleComplete || pipeInStream.full())break;wait(10);}@@ -124,7 +141,7 @@ InterruptedException {getReader(); // spawn parsing threadwhile (true) {synchronized(this) {- if (summary.length() >= SUMMARY_LENGTH)+ if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())break;wait(10);}@@ -134,16 +151,18 @@ InterruptedException {String sum = summary.toString().trim();String tit = getTitle();- if (sum.startsWith(tit))- return sum.substring(tit.length());+ if (sum.startsWith(tit) || sum.equals(""))+ return tit;elsereturn sum;}public Reader getReader() throws IOException {if (pipeIn == null) {- pipeIn = new PipedReader();- pipeOut = new PipedWriter(pipeIn);+ pipeInStream = new MyPipedInputStream();+ pipeOutStream = new PipedOutputStream(pipeInStream);+ pipeIn = new InputStreamReader(pipeInStream);+ pipeOut = new OutputStreamWriter(pipeOutStream);Thread thread = new ParserThread(this);thread.start(); // start parsing