This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_9_9 in repository https://gitbox.apache.org/repos/asf/solr.git
commit ec085c78a01170046364805cf1d49f85f43eef5b Author: David Smiley <[email protected]> AuthorDate: Mon Aug 25 13:18:29 2025 -0400 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 9052441aac9a980fba8ba291acc1de2305108b4a) --- solr/CHANGES.txt | 2 ++ .../org/apache/solr/client/solrj/impl/Http2SolrClient.java | 1 + .../solr/client/solrj/impl/BasicHttpSolrClientTest.java | 7 +++++-- .../apache/solr/client/solrj/impl/Http2SolrClientTest.java | 14 +++++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d00bda80511..489b83e314b 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -16,6 +16,8 @@ Bug Fixes * SOLR-17860: DocBasedVersionConstraintsProcessorFactory now supports PULL replicas. (Houston Putman) +* SOLR-17871: Http2SolrClient wasn't honoring idle timeout configuration above 30 seconds -- a regression. (Thomas Wöckinger, David Smiley) + Dependency Upgrades --------------------- (No changes) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java index 7462798a06a..15c2d636a54 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java @@ -306,6 +306,7 @@ public class Http2SolrClient extends HttpSolrClientBase { asyncTracker.getMaxRequestsQueuedPerDestination()); httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, USER_AGENT)); httpClient.setConnectTimeout(builder.getConnectionTimeoutMillis()); + httpClient.setIdleTimeout(-1); // don't enforce an idle timeout at this level // note: idle & request timeouts are set per request var cookieStore = builder.getCookieStore(); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java index 6a8456310f2..698ea92a540 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java @@ -104,13 +104,16 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { public static class SlowStreamServlet extends HttpServlet { + public static final int PACKET_MS = 500; + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - IntStream.range(0, 10) + String countStr = req.getParameter("count"); + IntStream.range(0, countStr == null ? 10 : Integer.parseInt(countStr)) .forEach( i -> { try { - Thread.sleep(500); + Thread.sleep(PACKET_MS); resp.getOutputStream().write(String.valueOf(i).getBytes(StandardCharsets.UTF_8)); resp.getOutputStream().flush(); } catch (IOException | InterruptedException e) { diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java index 3e7cf777d63..745d82f7383 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java @@ -27,6 +27,9 @@ import java.util.Base64; import java.util.Collections; import java.util.HashMap; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.client.api.util.SolrVersion; import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.SolrClient; @@ -39,6 +42,7 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.eclipse.jetty.client.WWWAuthenticationProtocolHandler; import org.eclipse.jetty.http.HttpStatus; @@ -707,11 +711,13 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase { } // too little time to succeed - QueryRequest req = new QueryRequest(); + int packets = LuceneTestCase.RANDOM_MULTIPLIER == 1 ? 10 : 80; // 60 crosses a default timeout + long timeToSendMs = packets * BasicHttpSolrClientTest.SlowStreamServlet.PACKET_MS; + QueryRequest req = new QueryRequest(SolrParams.of("count", "" + packets)); req.setResponseParser(new InputStreamResponseParser(FILE_STREAM)); assertIsTimeout(expectThrows(SolrServerException.class, () -> oldClient.request(req))); - int newIdleTimeoutMs = 10 * 1000; // enough time to succeed + long newIdleTimeoutMs = timeToSendMs + 1000; // enough time to succeed try (Http2SolrClient idleTimeoutChangedClient = new Http2SolrClient.Builder(url) .withHttpClient(oldClient) @@ -721,7 +727,9 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase { assertEquals(newIdleTimeoutMs, idleTimeoutChangedClient.getIdleTimeout()); NamedList<Object> response = idleTimeoutChangedClient.request(req); try (InputStream is = (InputStream) response.get("stream")) { - assertEquals("0123456789", new String(is.readAllBytes(), StandardCharsets.UTF_8)); + String expect = + IntStream.range(0, packets).mapToObj(String::valueOf).collect(Collectors.joining()); + assertEquals(expect, new String(is.readAllBytes(), StandardCharsets.UTF_8)); } } }
