Skip to content

Apache Lucene open-source search software

SOLR-12290: Update assert messages about closing request / response streams.

markrmiller4c09a13afb44
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index 0419f975462..4f9ead4811a 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -519,6 +519,15 @@ public class SolrDispatchFilter extends BaseSolrFilter {
}
}
+ private static String CLOSE_RESPONSE_STREAM_MSG = "Attempted close of response output stream - in general you should not do this, "
+ + "you may spoil connection reuse and possibly disrupt a client. If you must close without actually needing to close, "
+ + "use a CloseShield*Stream. Closing or flushing the stream commits the response and prevents us from modifying it and "
+ + "closing the stream prevents us from gauranteeing ourselves that streams are fully read for proper connection reuse.";
+
+ private static String CLOSE_REQUEST_STREAM_MSG = "We should not normally close the request input stream - we prefer to let the"
+ + " container manage the lifecycle of these streams and we prefer streams to remain open so we can use our own code to "
+ + "ensure streams are fully read for connection reuse.";
+
/**
* Wrap the request's input stream with a close shield. If this is a
* retry, we will assume that the stream has already been wrapped and do nothing.
@@ -542,7 +551,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
// even though we skip closes, we let local tests know not to close so that a full understanding can take
// place
assert Thread.currentThread().getStackTrace()[2].getClassName().matches(
- "org\\.apache\\.(?:solr|lucene).*") ? false : true : "Attempted close of request input stream - never do this, you will spoil connection reuse and possibly disrupt a client";
+ "org\\.apache\\.(?:solr|lucene).*") ? false : true : CLOSE_REQUEST_STREAM_MSG;
this.stream = ClosedServletInputStream.CLOSED_SERVLET_INPUT_STREAM;
}
};
@@ -577,7 +586,8 @@ public class SolrDispatchFilter extends BaseSolrFilter {
// even though we skip closes, we let local tests know not to close so that a full understanding can take
// place
assert Thread.currentThread().getStackTrace()[2].getClassName().matches(
- "org\\.apache\\.(?:solr|lucene).*") ? false : true : "Attempted close of response output stream - never do this, you will spoil connection reuse and possibly disrupt a client";
+ "org\\.apache\\.(?:solr|lucene).*") ? false
+ : true : CLOSE_RESPONSE_STREAM_MSG;
stream = ClosedServletOutputStream.CLOSED_SERVLET_OUTPUT_STREAM;
}
};