Skip to content

Commit 95f410d

Browse files
dsmileyThomas Wöckinger
andcommitted
SOLR-17871: Http2SolrClient: fix idle timeout > 30 seconds (#3497)
Http2SolrClient wasn't honoring idle timeout configuration above 30 seconds -- a regression. --------- Co-authored-by: Thomas Wöckinger <[email protected]> (cherry picked from commit 9052441)
1 parent 446a9e5 commit 95f410d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Bug Fixes
5050

5151
* SOLR-17830: v1 Restore API no longer conflates backup-name and collection-name during validation. (Abhishek Umarjikar via Jason Gerlowski)
5252

53+
* SOLR-17871: Http2SolrClient wasn't honoring idle timeout configuration above 30 seconds -- a regression. (Thomas Wöckinger, David Smiley)
54+
5355
Dependency Upgrades
5456
---------------------
5557
(No changes)

solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ private HttpClient createHttpClient(Builder builder) {
306306
asyncTracker.getMaxRequestsQueuedPerDestination());
307307
httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, USER_AGENT));
308308
httpClient.setConnectTimeout(builder.getConnectionTimeoutMillis());
309+
httpClient.setIdleTimeout(-1); // don't enforce an idle timeout at this level
309310
// note: idle & request timeouts are set per request
310311

311312
var cookieStore = builder.getCookieStore();

solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
104104

105105
public static class SlowStreamServlet extends HttpServlet {
106106

107+
public static final int PACKET_MS = 500;
108+
107109
@Override
108110
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
109-
IntStream.range(0, 10)
111+
String countStr = req.getParameter("count");
112+
IntStream.range(0, countStr == null ? 10 : Integer.parseInt(countStr))
110113
.forEach(
111114
i -> {
112115
try {
113-
Thread.sleep(500);
116+
Thread.sleep(PACKET_MS);
114117
resp.getOutputStream().write(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
115118
resp.getOutputStream().flush();
116119
} catch (IOException | InterruptedException e) {

solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import java.util.Collections;
2828
import java.util.HashMap;
2929
import java.util.concurrent.TimeUnit;
30+
import java.util.stream.Collectors;
31+
import java.util.stream.IntStream;
32+
import org.apache.lucene.tests.util.LuceneTestCase;
3033
import org.apache.solr.client.api.util.SolrVersion;
3134
import org.apache.solr.client.solrj.ResponseParser;
3235
import org.apache.solr.client.solrj.SolrClient;
@@ -39,6 +42,7 @@
3942
import org.apache.solr.common.params.CommonParams;
4043
import org.apache.solr.common.params.MapSolrParams;
4144
import org.apache.solr.common.params.ModifiableSolrParams;
45+
import org.apache.solr.common.params.SolrParams;
4246
import org.apache.solr.common.util.NamedList;
4347
import org.eclipse.jetty.client.WWWAuthenticationProtocolHandler;
4448
import org.eclipse.jetty.http.HttpStatus;
@@ -707,11 +711,13 @@ public void testIdleTimeoutWithHttpClient() throws Exception {
707711
}
708712

709713
// too little time to succeed
710-
QueryRequest req = new QueryRequest();
714+
int packets = LuceneTestCase.RANDOM_MULTIPLIER == 1 ? 10 : 80; // 60 crosses a default timeout
715+
long timeToSendMs = packets * BasicHttpSolrClientTest.SlowStreamServlet.PACKET_MS;
716+
QueryRequest req = new QueryRequest(SolrParams.of("count", "" + packets));
711717
req.setResponseParser(new InputStreamResponseParser(FILE_STREAM));
712718
assertIsTimeout(expectThrows(SolrServerException.class, () -> oldClient.request(req)));
713719

714-
int newIdleTimeoutMs = 10 * 1000; // enough time to succeed
720+
long newIdleTimeoutMs = timeToSendMs + 1000; // enough time to succeed
715721
try (Http2SolrClient idleTimeoutChangedClient =
716722
new Http2SolrClient.Builder(url)
717723
.withHttpClient(oldClient)
@@ -721,7 +727,9 @@ public void testIdleTimeoutWithHttpClient() throws Exception {
721727
assertEquals(newIdleTimeoutMs, idleTimeoutChangedClient.getIdleTimeout());
722728
NamedList<Object> response = idleTimeoutChangedClient.request(req);
723729
try (InputStream is = (InputStream) response.get("stream")) {
724-
assertEquals("0123456789", new String(is.readAllBytes(), StandardCharsets.UTF_8));
730+
String expect =
731+
IntStream.range(0, packets).mapToObj(String::valueOf).collect(Collectors.joining());
732+
assertEquals(expect, new String(is.readAllBytes(), StandardCharsets.UTF_8));
725733
}
726734
}
727735
}

0 commit comments

Comments
 (0)