This is an automated email from the ASF dual-hosted git repository.
martijnvisser pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 9f20f1d0e5c [FLINK-39180][tests] Fix flaky
RestClientTest.testRestClientClosedHandling
9f20f1d0e5c is described below
commit 9f20f1d0e5cdf3168b294284114ea9ace06576a4
Author: Martijn Visser <[email protected]>
AuthorDate: Sat Feb 28 05:43:36 2026 -0800
[FLINK-39180][tests] Fix flaky RestClientTest.testRestClientClosedHandling
The test was failing in CI with the following error:
RestClientTest.testRestClientClosedHandling:249
Expecting a throwable with cause being an instance of:
java.io.IOException
but was an instance of:
java.lang.IllegalStateException
Root cause: FLINK-32583 changed RestClient behavior to throw
IllegalStateException when closed to prevent deadlocks, but the
test was never updated from its original IOException expectation.
The test now accepts both IllegalStateException and IOException
since a race condition exists:
- IllegalStateException with message "RestClient closed before
request completed": Thrown by
RestClient#notifyResponseFuturesOfShutdown() when close() is
called before connection establishes
- ConnectionClosedException (extends IOException): Thrown by
RestClient.ClientHandler#channelInactive() when connection is
established but becomes inactive due to client closure
Both are valid outcomes when closing the client with a request
in-flight. The race is confirmed by test behavior:
- Run alone: Gets IllegalStateException consistently
- Run with other tests: Gets ConnectionClosedException
Added message verification for IllegalStateException to ensure
we catch the expected exception from
notifyResponseFuturesOfShutdown()
---
.../apache/flink/runtime/rest/RestClientTest.java | 27 ++++++++++++++++++++--
1 file changed, 25 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 a15913ef09a..bbad7c7df1c 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
@@ -205,7 +205,15 @@ class RestClientTest {
}
}
- /** Tests that we fail the operation if the client closes. */
+ /**
+ * Tests that we fail the operation if the client closes.
+ *
+ * <p>The exact exception depends on timing.
+ *
+ * <p>Both are valid outcomes when the client is closed with a request
in-flight.
+ *
+ * <p>See FLINK-39180
+ */
@Test
void testRestClientClosedHandling() throws Exception {
final Configuration config = new Configuration();
@@ -244,9 +252,24 @@ class RestClientTest {
restClient.close();
+ // Both exceptions are valid depending on timing (see javadoc)
FlinkAssertions.assertThatFuture(responseFuture)
.eventuallyFailsWith(ExecutionException.class)
- .withCauseInstanceOf(IOException.class);
+ .satisfies(
+ e ->
+ assertThat(e.getCause())
+ .satisfiesAnyOf(
+ c ->
+ assertThat(c)
+
.isInstanceOf(
+
IllegalStateException
+
.class)
+
.hasMessage(
+
"RestClient closed before request completed"),
+ c ->
+ assertThat(c)
+
.isInstanceOf(
+
IOException.class)));
} finally {
if (connectionSocket != null) {
connectionSocket.close();