From 093b1752134a427303ae590f4131d9764f425bb7 Mon Sep 17 00:00:00 2001 From: Martijn Visser <2989614+MartijnVisser@users.noreply.github.com> Date: Wed, 18 Feb 2026 11:06:00 +0100 Subject: [PATCH] [FLINK-39105][rest] Fix RestClientTest.testConnectionTimeout to handle environment-dependent exception types The test connects to 240.0.0.0 (reserved space, RFC 1112) with a 1ms connection timeout and asserts ConnectTimeoutException. On CI runners without a route to this address, the OS immediately returns "Network is unreachable" (AnnotatedSocketException) instead of timing out, causing the test to fail. Both ConnectTimeoutException and AnnotatedSocketException are SocketException subtypes, so the assertion now uses SocketException as the expected cause type. The existing hasMessageContaining(unroutableIp) check still verifies the failure is for the correct destination. Note: on environments where the OS rejects immediately, the configured connection timeout is never exercised. The test still verifies that connection failures propagate correctly, but does not validate the timeout code path on those environments. A more robust approach would require simulating a non-completing TCP handshake, which is not portable. (cherry picked from commit fdc2686e33d8dd1a338e3cc1432a6b8b2cad6d71) --- .../org/apache/flink/runtime/rest/RestClientTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java index cd6b76ec6a2d6..ac91c0ca77b85 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java @@ -36,7 +36,6 @@ import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty; import org.apache.flink.shaded.netty4.io.netty.channel.Channel; -import org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException; import org.apache.flink.shaded.netty4.io.netty.channel.DefaultSelectStrategyFactory; import org.apache.flink.shaded.netty4.io.netty.channel.SelectStrategy; import org.apache.flink.shaded.netty4.io.netty.channel.SelectStrategyFactory; @@ -51,6 +50,7 @@ import java.lang.reflect.Field; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; import java.time.Duration; import java.util.Arrays; import java.util.Collections; @@ -107,9 +107,13 @@ void testConnectionTimeout() throws Exception { EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance()); + // Depending on the environment, connecting to a non-routable address may fail with + // either a ConnectTimeoutException (timeout fires before the OS responds) or a + // SocketException such as "Network is unreachable" (OS rejects immediately). + // Both are SocketException subtypes. FlinkAssertions.assertThatFuture(future) .eventuallyFailsWith(ExecutionException.class) - .withCauseInstanceOf(ConnectTimeoutException.class) + .withCauseInstanceOf(SocketException.class) .extracting(Throwable::getCause, as(InstanceOfAssertFactories.THROWABLE)) .hasMessageContaining(unroutableIp); }