Merge pull request #4882 from eclipse/jetty-9.4.x-4873-ExecutorThreadPoolJoin

Issue #4873 - fix timeout on ExecutorThreadPool.join()
This commit is contained in:
Lachlan 2020-05-25 14:07:28 +10:00 committed by GitHub
commit 4611379c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -302,7 +302,7 @@ public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool
@Override
public void join() throws InterruptedException
{
_executor.awaitTermination(getStopTimeout(), TimeUnit.MILLISECONDS);
_executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
@Override

View File

@ -18,7 +18,11 @@
package org.eclipse.jetty.util.thread;
import java.time.Duration;
import org.eclipse.jetty.util.ProcessorUtils;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
@ -26,6 +30,8 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.fail;
public abstract class AbstractThreadPoolTest
@ -87,4 +93,26 @@ public abstract class AbstractThreadPoolTest
assertThat(pool.getMaxThreads(), Matchers.is(3));
}
@Test
public void testJoinWithStopTimeout()
{
// ThreadPool must be an implement ContainerLifeCycle for this test to be valid.
SizedThreadPool threadPool = newPool(3);
if (!(threadPool instanceof ContainerLifeCycle))
return;
final long stopTimeout = 100;
((ContainerLifeCycle)threadPool).setStopTimeout(100);
LifeCycle.start(threadPool);
// Verify that join does not timeout after waiting twice the stopTimeout.
assertThrows(Throwable.class, () ->
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout * 2), threadPool::join)
);
// After stopping the ThreadPool join should unblock.
LifeCycle.stop(threadPool);
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout), threadPool::join);
}
}