X Tutup
Skip to content

Commit 0d08a33

Browse files
authored
Fix #1492 by using awaitStarted() to preserve the order if invocations (#1494)
The problem is that using `awaitStarted()` on `attach`'s callback on a non-running container leads to the infinite wait for Jersey transport implementation. This happens when `SelectiveLoggingFilter` is used in `DefaultInvocationBuilder` where it is created with `printEntity = true` parameter. In this case the implementation of `ClientResponseFilter.filter(...)` method in the base `LoggingFilter` class blocks at `responseContext.hasEntity()` until the data is available in the response. This happens because `hasEntity()` reads a single byte to check whether there is any data available in the stream. In the case of `attach` command this method blocks until there is data in stdout/stderr streams. Having data from the streams requires container running, which we cannot do safely without `awaitStarted()` because `attach` command is performed in a separate thread and we need to run `start` only _after_ `attach` request is executed not to loose the data from stdout/stderr streams.
1 parent ce5e9eb commit 0d08a33

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

docker-java-transport-jersey/src/main/java/com/github/dockerjava/jaxrs/JerseyDockerHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private JerseyDockerHttpClient(
165165
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
166166

167167
// logging may disabled via log level
168-
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
168+
clientConfig.register(new SelectiveLoggingFilter(LOGGER, false));
169169

170170
if (readTimeout != null) {
171171
requestConfigBuilder.setSocketTimeout(readTimeout);

docker-java/src/test/java/com/github/dockerjava/cmd/AttachContainerCmdIT.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import static org.hamcrest.Matchers.emptyString;
2929
import static org.hamcrest.Matchers.equalTo;
3030
import static org.hamcrest.Matchers.not;
31-
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assert.assertTrue;
31+
import static org.junit.Assert.*;
3332

3433
/**
3534
* @author Kanstantsin Shautsou
@@ -80,6 +79,9 @@ public void onNext(Frame frame) {
8079
.withStdIn(in)
8180
.exec(callback);
8281

82+
assertTrue("Processing of the response should start shortly after executing `attachContainerCmd`",
83+
callback.awaitStarted(5, SECONDS));
84+
8385
dockerClient.startContainerCmd(container.getId()).exec();
8486

8587
out.write((snippet + "\n").getBytes());
@@ -123,6 +125,9 @@ public void onNext(Frame frame) {
123125
.withLogs(true)
124126
.exec(callback);
125127

128+
assertTrue("Processing of the response should start shortly after executing `attachContainerCmd`",
129+
callback.awaitStarted(5, SECONDS));
130+
126131
dockerClient.startContainerCmd(container.getId()).exec();
127132

128133
callback.awaitCompletion(30, TimeUnit.SECONDS);
@@ -164,6 +169,9 @@ public void onNext(Frame frame) {
164169
.withFollowStream(true)
165170
.exec(callback);
166171

172+
assertTrue("Processing of the response should start shortly after executing `attachContainerCmd`",
173+
callback.awaitStarted(5, SECONDS));
174+
167175
dockerClient.startContainerCmd(container.getId()).exec();
168176

169177
callback.awaitCompletion(15, TimeUnit.SECONDS);
@@ -213,6 +221,9 @@ public void onNext(Frame frame) {
213221
.withStdIn(stdin)
214222
.exec(callback);
215223

224+
assertFalse("Processing of the response is not expected to be started" +
225+
" because `attachContainerCmd` with stdin is not supported", callback.awaitStarted(5, SECONDS));
226+
216227
dockerClient.startContainerCmd(container.getId()).exec();
217228

218229
callback.awaitCompletion(30, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)
X Tutup