Skip to content

Commit

Permalink
#11692 alternative fix: run leftover tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Apr 26, 2024
1 parent f9a8510 commit 7596503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Expand Up @@ -148,6 +148,25 @@ public void onClose(Throwable cause)
super.onClose(cause);

LifeCycle.stop(strategy);

// Run the tasks remaining after the strategy was stopped
Queue<Runnable> copy;
try (AutoLock ignored = lock.lock())
{
copy = new ArrayDeque<>(tasks);
tasks.clear();
}
copy.forEach(task ->
{
try
{
task.run();
}
catch (Throwable x)
{
LOG.warn("Error running leftover task during onClose", x);
}
});
}

@Override
Expand Down
Expand Up @@ -79,7 +79,6 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -1150,17 +1149,9 @@ public void close() throws IOException

assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
assertTrue(closeLatch.await(5, TimeUnit.SECONDS));
// Since the connector was stopped, there is no guarantee that
// the pending demand got serviced with an error chunk.
if (serverDemandLatch.await(5, TimeUnit.SECONDS))
{
assertTrue(Content.Chunk.isFailure(lastChunk.get(), true));
assertInstanceOf(IOException.class, lastChunk.get().getFailure());
}
else
{
assertThat(lastChunk.get(), is(nullValue()));
}
assertTrue(serverDemandLatch.await(5, TimeUnit.SECONDS));
assertTrue(Content.Chunk.isFailure(lastChunk.get(), true));
assertInstanceOf(IOException.class, lastChunk.get().getFailure());
}

@ParameterizedTest
Expand Down

0 comments on commit 7596503

Please sign in to comment.