parallec icon indicating copy to clipboard operation
parallec copied to clipboard

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

Open kefasb opened this issue 5 years ago • 1 comments

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: https://github.com/eBay/parallec/blob/1b4f1628f34fedfb06b24c33a5372d64d3df0952/src/main/java/io/parallec/core/ParallelTaskBuilder.java#L278

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.

kefasb avatar Oct 25 '18 09:10 kefasb

@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?

jeffpeiyt avatar Oct 26 '18 05:10 jeffpeiyt