Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;

class DefaultInvocationBuilder implements InvocationBuilder {
Expand Down Expand Up @@ -264,7 +265,11 @@ protected <T> void executeAndStream(
ResultCallback<T> callback,
Consumer<DockerHttpClient.Response> sourceConsumer
) {
CountDownLatch threadStarted = new CountDownLatch(1);

Thread thread = new Thread(() -> {
threadStarted.countDown();

Thread streamingThread = Thread.currentThread();
try (DockerHttpClient.Response response = execute(request)) {
callback.onStart(() -> {
Expand All @@ -281,6 +286,13 @@ protected <T> void executeAndStream(
thread.setDaemon(true);

thread.start();

try {
// wait while the thread is actually started to let the request a better chances to be executed prior to a next request
threadStarted.await();
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}

private InputStream encode(Object entity) {
Expand Down