Skip to content
This repository has been archived by the owner on Jan 1, 2019. It is now read-only.

ParallelTaskBuilder.execute hangs forever waiting for a task completion in sync mode after resources released #89

Open
kefasb opened this issue Oct 25, 2018 · 1 comment

Comments

@kefasb
Copy link

kefasb commented Oct 25, 2018

When ParallelClient.releaseExternalResources is called while ParallelTaskBuilder.execute is waiting for a task to complete is sync mode then ParallelTaskBiulder hangs forever in this while:

while (task != null && !task.isCompleted()) {

Even calling interrupt on executing thread (or shutdownNow on executor) does not have a result, because interrupts are swallowed.

Code snippet to reproduce:

    private static final Duration RELEASE_TIMEOUT = Duration.ofSeconds(3);
    private static final AtomicInteger PING_THREAD_ID_GEN = new AtomicInteger();

    public static void main(String[] args) {

        final ExecutorService pingExecutor = Executors.newSingleThreadExecutor(
            r -> new Thread(r, "PingThread-" + PING_THREAD_ID_GEN.incrementAndGet()));
        pingExecutor.submit(() -> ping());

        final ScheduledExecutorService releaseScheduledExecutor = Executors.newSingleThreadScheduledExecutor();
        releaseScheduledExecutor.schedule(() -> {
            new ParallelClient().releaseExternalResources();
            pingExecutor.shutdownNow();
            releaseScheduledExecutor.shutdownNow();
        }, RELEASE_TIMEOUT.getSeconds(), TimeUnit.SECONDS);
    }

    private static void ping() {
       new ParallelClient().preparePing()
                            .setPingNumRetries(0)
                            .setPingTimeoutMillis((int) RELEASE_TIMEOUT.plus(Duration.ofMillis(1000)).toMillis())
                            .setTargetHostsFromList(Collections.singletonList("1.2.3.4"))
                            .execute((result, responseContext) -> System.out.println(result));
    }

Result: PingThread-1 is sleeping forever.

Could you add !Thread.currentThread().isInterrupted() condition to the while (if this will not break anything else :) )? Or react on interruption in some way.

@jeffpeiyt
Copy link
Contributor

@kefasb thanks so much for trying parallec. Normally i do not need to run the releaseExternalResources if running as a server. what is the use case we need to release all the resources?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants