Apache Solr open-source search software
SOLR-18027 Proper fix for anotra bundle download timeout (#3952)
Jan Høydahlc7706feb09f7
diff --git a/solr/solr-ref-guide/build.gradle b/solr/solr-ref-guide/build.gradleindex c791c4978f3..4dced1fdacc 100644--- a/solr/solr-ref-guide/build.gradle+++ b/solr/solr-ref-guide/build.gradle@@ -405,15 +405,15 @@ task buildLocalAntoraSite(type: NpxTask) {"--fetch"] + extraArgs- // Configure undici HTTP timeout via preload script to prevent timeout errors+ // Configure HTTP request timeout via preload script to prevent timeout errors// when downloading UI bundle from slow networks (especially in CI)- def nodeOptions = "--require ${projectDir}/increase-undici-timeout.js"+ def nodeOptions = "--require ${projectDir}/increase-request-timeout.js"environment = ["SITE_SEARCH_ENABLED": "true","MATOMO_ENABLED": "false","NODE_OPTIONS": nodeOptions,- "UNDICI_TIMEOUT_MS": "60000" // 60 seconds timeout+ "HTTP_REQUEST_TIMEOUT_MS": "60000" // 60 seconds timeout]inputs.files(fileTree(project.ext.siteStagingDir))@@ -509,15 +509,15 @@ task buildOfficialSite(type: NpxTask) {officialPlaybook,] + extraArgs- // Configure undici HTTP timeout via preload script to prevent timeout errors+ // Configure HTTP request timeout via preload script to prevent timeout errors// when downloading UI bundle from slow networks (especially in CI)- def nodeOptions = "--require ${projectDir}/increase-undici-timeout.js"+ def nodeOptions = "--require ${projectDir}/increase-request-timeout.js"environment = ["SITE_SEARCH_ENABLED": "true","MATOMO_ENABLED": "true","NODE_OPTIONS": nodeOptions,- "UNDICI_TIMEOUT_MS": "60000" // 60 seconds timeout+ "HTTP_REQUEST_TIMEOUT_MS": "60000" // 60 seconds timeout]inputs.files(officialPlaybook)diff --git a/solr/solr-ref-guide/increase-request-timeout.js b/solr/solr-ref-guide/increase-request-timeout.jsnew file mode 100644index 00000000000..f29bc7bc887--- /dev/null+++ b/solr/solr-ref-guide/increase-request-timeout.js@@ -0,0 +1,59 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/**+ * Preload script to increase HTTP request timeout for Antora UI bundle downloads.+ *+ * This script intercepts HTTP/HTTPS requests to set longer timeout values, preventing+ * timeout errors when downloading the UI bundle from slow or high-latency networks,+ * particularly in CI environments.+ *+ * Issue: Antora's UI bundle downloads (925KB from Apache's nightlies server) can timeout+ * on slow networks. The simple-get library used by Antora doesn't set request timeouts+ * by default, so we intercept http.request() and https.request() to add them.+ *+ * Usage: This script is preloaded via NODE_OPTIONS in the buildLocalAntoraSite task.+ */++// Configuration via environment variable+const timeoutMs = parseInt(process.env.HTTP_REQUEST_TIMEOUT_MS || '60000', 10);++// Configure HTTP request timeouts by intercepting request methods+try {+ const http = require('node:http');+ const https = require('node:https');++ // Intercept http.request to add timeout to each request+ const originalHttpRequest = http.request;+ http.request = function(...args) {+ const req = originalHttpRequest.apply(this, args);+ req.setTimeout(timeoutMs);+ console.log(`[http-timeout] Modified http request to set timeout ${timeoutMs}ms`);+ return req;+ };++ // Intercept https.request to add timeout to each request+ const originalHttpsRequest = https.request;+ https.request = function(...args) {+ const req = originalHttpsRequest.apply(this, args);+ req.setTimeout(timeoutMs);+ console.log(`[http-timeout] Modified https request to set timeout ${timeoutMs}ms`);+ return req;+ };+} catch (error) {+ console.warn('[http-timeout] Could not configure HTTP request timeouts:', error.message);+}diff --git a/solr/solr-ref-guide/increase-undici-timeout.js b/solr/solr-ref-guide/increase-undici-timeout.jsdeleted file mode 100644index 3940fe951d7..00000000000--- a/solr/solr-ref-guide/increase-undici-timeout.js+++ /dev/null@@ -1,45 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--/**- * Preload script to increase undici HTTP timeout for Antora UI bundle downloads.- *- * This script sets the global HTTP agent with longer timeout values to prevent- * timeout errors when downloading the UI bundle from slow or high-latency networks,- * particularly in CI environments.- *- * Issue: Node.js 20+ includes undici with default timeouts that may be too short- * for downloading the Antora UI bundle (925KB) from Apache's nightlies server.- *- * Usage: This script is preloaded via NODE_OPTIONS in the buildLocalAntoraSite task.- */--// Configuration via environment variable-const timeoutMs = parseInt(process.env.UNDICI_TIMEOUT_MS || '60000', 10);--// Configure HTTP agent timeouts-try {- const http = require('node:http');- const https = require('node:https');-- http.globalAgent.timeout = timeoutMs;- https.globalAgent.timeout = timeoutMs;-- console.log(`[undici-timeout] Configured HTTP agent timeouts: ${timeoutMs}ms`);-} catch (error) {- console.warn('[undici-timeout] Could not configure HTTP agent timeouts:', error.message);-}