[#2398] FutureBrokerInfoTimeout is missed due to logic operator error - #2399
Open
mattrpav wants to merge 2 commits into
Open
[#2398] FutureBrokerInfoTimeout is missed due to logic operator error#2399mattrpav wants to merge 2 commits into
mattrpav wants to merge 2 commits into
Conversation
The timed get loop's condition uses || between the not-disposed check and the deadline check, so the loop runs until disposal regardless of the caller's timeout. Widens FutureBrokerInfo to package-private so the test drives the real class. Two of four scenarios fail until the condition is corrected.
Correct the loop condition from || to && so the timed get exits when EITHER the bridge is disposed OR the deadline expires. Previously a peer that never delivered its BrokerInfo parked the bridge start thread until disposal, ignoring the caller's timeout.
cshannon
requested changes
Aug 4, 2026
| AtomicBoolean timedOut = new AtomicBoolean(false); | ||
| AtomicLong elapsed = new AtomicLong(-1); | ||
|
|
||
| Thread t = new Thread(() -> { |
Contributor
There was a problem hiding this comment.
I would re-write these tests and use an executor, it's simpler/cleaner. Here's an example for this test but it applies to all the tests.
@Test(timeout = 10000)
public void testGetTimedThrowsTimeoutExceptionWithinTimeout() throws Exception {
AtomicBoolean disposed = new AtomicBoolean(false);
FutureBrokerInfo future = new FutureBrokerInfo(null, disposed);
AtomicBoolean timedOut = new AtomicBoolean(false);
AtomicLong elapsed = new AtomicLong(-1);
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
long start = System.currentTimeMillis();
try {
future.get(200, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
timedOut.set(true);
} catch (Exception ignored) {
} finally {
elapsed.set(System.currentTimeMillis() - start);
}
});
executor.shutdown();
assertTrue("get(200ms) should have returned within 3s but is still blocked "
+ "- the timeout is being ignored",
executor.awaitTermination(3, TimeUnit.SECONDS));
assertTrue("Expected TimeoutException from get(200ms)", timedOut.get());
assertTrue("Timed out too early: " + elapsed.get() + "ms", elapsed.get() >= 180);
}
Contributor
There was a problem hiding this comment.
also it might be worth wrapping the assertion in a try/finally just in case it get stuck:
try {
assertTrue("get(200ms) should have returned within 3s but is still blocked "
+ "- the timeout is being ignored",
executor.awaitTermination(3, TimeUnit.SECONDS));
} finally {
executor.shutdownNow();
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.