Skip to content
This repository was archived by the owner on Jan 1, 2019. It is now read-only.
This repository was 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

@kefasb

Description

@kefasb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions