Skip to content

Commit 841250d

Browse files
authored
Allow more time for startup to fix jenkins failures (#2903)
1 parent 75c3730 commit 841250d

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

tika-pipes/tika-pipes-core/src/main/java/org/apache/tika/pipes/core/PipesClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ private void reconnect() throws InterruptedException, IOException, TimeoutExcept
304304
int port = serverManager.getPort();
305305
LOG.debug("pipesClientId={}: connecting to server", pipesClientId);
306306

307-
// Connect to server
308-
Socket socket = serverManager.connect((int) pipesConfig.getSocketTimeoutMs());
307+
// Connect to server. Use the generous startup timeout as the read SO_TIMEOUT so the
308+
// server's post-connect initialization and READY handshake aren't bounded by the
309+
// (possibly tight) per-request socketTimeoutMs.
310+
Socket socket = serverManager.connect((int) pipesConfig.getStartupTimeoutMs());
309311

310312
synchronized (connectionLock) {
311313
connectionTuple = new ConnectionTuple(socket,
@@ -314,6 +316,8 @@ private void reconnect() throws InterruptedException, IOException, TimeoutExcept
314316
}
315317

316318
waitForStartup();
319+
// Server is ready; subsequent reads use the normal per-request socket timeout.
320+
socket.setSoTimeout((int) pipesConfig.getSocketTimeoutMs());
317321
}
318322

319323
private void writeTask(FetchEmitTuple t) throws IOException {

tika-pipes/tika-pipes-core/src/main/java/org/apache/tika/pipes/core/PipesConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class PipesConfig {
3737

3838
public static final long DEFAULT_SOCKET_TIMEOUT_MS = 60000;
3939

40+
public static final long DEFAULT_STARTUP_TIMEOUT_MS = 60000;
41+
4042
public static final long DEFAULT_HEARTBEAT_INTERVAL_MS = 1000;
4143

4244
public static final boolean DEFAULT_USE_SHARED_SERVER = false;
@@ -55,6 +57,7 @@ public class PipesConfig {
5557
private boolean useSharedServer = DEFAULT_USE_SHARED_SERVER;
5658

5759
private long socketTimeoutMs = DEFAULT_SOCKET_TIMEOUT_MS;
60+
private long startupTimeoutMs = DEFAULT_STARTUP_TIMEOUT_MS;
5861
private long heartbeatIntervalMs = DEFAULT_HEARTBEAT_INTERVAL_MS;
5962

6063
private long shutdownClientAfterMillis = DEFAULT_SHUTDOWN_CLIENT_AFTER_MILLS;
@@ -161,6 +164,21 @@ public void setSocketTimeoutMs(long socketTimeoutMs) {
161164
this.socketTimeoutMs = socketTimeoutMs;
162165
}
163166

167+
public long getStartupTimeoutMs() {
168+
return startupTimeoutMs;
169+
}
170+
171+
/**
172+
* Timeout in milliseconds for the forked server to start up and send its READY handshake.
173+
* Distinct from {@link #getSocketTimeoutMs()}: cold-starting the forked JVM (loading config,
174+
* parsers and plugins) can take far longer than a normal per-read timeout, so the handshake
175+
* gets its own generous budget. Once the server is ready, reads switch to {@code socketTimeoutMs}.
176+
* @param startupTimeoutMs
177+
*/
178+
public void setStartupTimeoutMs(long startupTimeoutMs) {
179+
this.startupTimeoutMs = startupTimeoutMs;
180+
}
181+
164182
public long getHeartbeatIntervalMs() {
165183
return heartbeatIntervalMs;
166184
}

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/PipesClientTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ public void testSocketTimeout(@TempDir Path tmp) throws Exception {
396396
PipesResult pipesResult = pipesClient.process(tuple);
397397
long elapsed = System.currentTimeMillis() - startTime;
398398

399-
// Should timeout due to socket timeout (no heartbeats received within socketTimeoutMs)
400-
// fails with FAILED_TO_INITIALIZE when using mchange-commons-java 0.5.0
399+
// Should timeout due to socket timeout (no heartbeats received within socketTimeoutMs).
400+
// Startup/handshake is bounded by startupTimeoutMs (not socketTimeoutMs), so a slow
401+
// fork cold-start no longer misfires here as FAILED_TO_INITIALIZE.
401402
assertEquals(PipesResult.RESULT_STATUS.TIMEOUT, pipesResult.status(),
402403
"Should timeout when socket times out");
403404

404-
// Socket timeout is 3 seconds; allow generous headroom for slow CI runners
405-
// where the server may need multiple startup attempts before connecting.
405+
// Socket timeout is 3 seconds; allow generous headroom for slow CI runners.
406406
assertTrue(elapsed < 60000,
407407
"Socket timeout should occur within 60s (elapsed: " + elapsed + "ms)");
408408

0 commit comments

Comments
 (0)