From f490fa3802f6e2ad5c36022fb5e59f38da6a6c2b Mon Sep 17 00:00:00 2001 From: Vasiliy Mikhailov Date: Fri, 26 Jun 2026 09:04:36 +0300 Subject: [PATCH] Restore the interrupt status in UrlChecker.waitUntilUnavailable waitUntilUnavailable caught InterruptedException and rethrew it wrapped in a RuntimeException without re-setting the thread interrupt flag, unlike the sibling waitUntilAvailable. Re-set the flag so callers can still observe the interruption. --- .../org/openqa/selenium/net/UrlChecker.java | 5 +++- .../openqa/selenium/net/UrlCheckerTest.java | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/net/UrlChecker.java b/java/src/org/openqa/selenium/net/UrlChecker.java index 44437f2a463c8..e12d9492350c7 100644 --- a/java/src/org/openqa/selenium/net/UrlChecker.java +++ b/java/src/org/openqa/selenium/net/UrlChecker.java @@ -154,7 +154,10 @@ public void waitUntilUnavailable(long timeout, TimeUnit unit, final URL url) "Timed out waiting for %s to become unavailable after %d ms", url, System.currentTimeMillis() - start), e); - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } catch (ExecutionException e) { throw new RuntimeException(e); } } diff --git a/java/test/org/openqa/selenium/net/UrlCheckerTest.java b/java/test/org/openqa/selenium/net/UrlCheckerTest.java index 2d36293df9349..58b74b7983572 100644 --- a/java/test/org/openqa/selenium/net/UrlCheckerTest.java +++ b/java/test/org/openqa/selenium/net/UrlCheckerTest.java @@ -102,4 +102,33 @@ public void cleanup() { safelyCall(() -> server.stop()); safelyCall(executorService::shutdownNow); } + + @Test + void waitUntilUnavailablePreservesInterruptStatus() throws Exception { + Thread caller = Thread.currentThread(); + Thread interrupter = + new Thread( + () -> { + try { + Thread.sleep(500); + } catch (InterruptedException ignored) { + } + caller.interrupt(); + }); + interrupter.start(); + + boolean threw = false; + boolean preserved = false; + try { + urlChecker.waitUntilUnavailable(10, TimeUnit.SECONDS, url); + } catch (RuntimeException expected) { + threw = true; + preserved = Thread.currentThread().isInterrupted(); + Thread.interrupted(); + } + interrupter.join(); + + assertThat(threw).isTrue(); + assertThat(preserved).isTrue(); + } }