Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-8669: Non binary responses use chunked encoding because we flush the outputstream early.

markrmiller13dda5debbb7
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e00bf6bf555..7584f45210b 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -188,6 +188,9 @@ Optimizations
* SOLR-8532: Optimize GraphQuery when maxDepth is set by not collecting edges at the maxDepth level.
(Kevin Watters via yonik)
+* SOLR-8669: Non binary responses use chunked encoding because we flush the outputstream early.
+ (Mark Miller)
+
Other Changes
----------------------
@@ -533,7 +536,7 @@ Bug Fixes
* SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we
count on HttpClient or the JVM. (Mark Miller)
-
+
Optimizations
----------------------
@@ -544,6 +547,9 @@ Optimizations
* SOLR-7281: Add an overseer action to publish an entire node as 'down'. (Mark Miller, shalin)
+* SOLR-8669: Non binary responses use chunked encoding because we flush the outputstream early.
+ (Mark Miller)
+
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/response/QueryResponseWriterUtil.java b/solr/core/src/java/org/apache/solr/response/QueryResponseWriterUtil.java
index bd56141758f..64875375ebf 100644
--- a/solr/core/src/java/org/apache/solr/response/QueryResponseWriterUtil.java
+++ b/solr/core/src/java/org/apache/solr/response/QueryResponseWriterUtil.java
@@ -48,7 +48,20 @@ public final class QueryResponseWriterUtil {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter;
binWriter.write(outputStream, solrRequest, solrResponse);
} else {
- Writer writer = buildWriter(outputStream, ContentStreamBase.getCharsetFromContentType(contentType));
+ OutputStream out = new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ outputStream.write(b);
+ }
+ @Override
+ public void flush() throws IOException {
+ // We don't flush here, which allows us to flush below
+ // and only flush internal buffers, not the response.
+ // If we flush the response early, we trigger chunked encoding.
+ // See SOLR-8669.
+ }
+ };
+ Writer writer = buildWriter(out, ContentStreamBase.getCharsetFromContentType(contentType));
responseWriter.write(writer, solrRequest, solrResponse);
writer.flush();
}
diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
index 3578cec2dad..fa9d92a6736 100644
--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
@@ -580,7 +580,6 @@ public class HttpSolrCall {
OutputStream os = resp.getOutputStream();
IOUtils.copyLarge(is, os);
- os.flush();
}
} catch (IOException e) {