Skip to content

Commit 39f5e4a

Browse files
committed
[wip] add logs to debug /attach on windows
1 parent 0cd320c commit 39f5e4a

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

engine/src/main/java/de/gesellix/docker/engine/OkResponseCallback.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,31 @@ public void onResponse(@NotNull final Call call, @NotNull final Response respons
5151
Thread writer = new Thread(() -> {
5252
try {
5353
final BufferedSink bufferedSink = Okio.buffer(getConnectionProvider().getSink());
54-
bufferedSink.writeAll(stdinSource);
54+
long written = bufferedSink.writeAll(stdinSource);
55+
log.warn("xxxxx - writer - written " + written);
5556
bufferedSink.flush();
57+
log.warn("xxxxx - writer - flushed");
5658
attachConfig.onSinkWritten(response);
59+
log.warn("xxxxx - writer - onSinkWritten");
5760
CountDownLatch done = new CountDownLatch(1);
5861
delayed(100, "writer", () -> {
62+
log.warn("xxxxx - writer - delayed");
5963
try {
6064
bufferedSink.close();
65+
log.warn("xxxxx - writer - delayed closed");
6166
attachConfig.onSinkClosed(response);
67+
log.warn("xxxxx - writer - delayed onSinkClosed");
6268
}
6369
catch (Exception e) {
6470
log.warn("error", e);
6571
}
72+
log.warn("xxxxx - writer - delayed return");
6673
return null;
6774
}, done);
68-
done.await(5, TimeUnit.SECONDS);
75+
boolean inTime = done.await(5, TimeUnit.SECONDS);
76+
if (!inTime) {
77+
log.warn("xxxxx - writer - done timeout");
78+
}
6979
}
7080
catch (InterruptedException e) {
7181
log.debug("stdin->sink interrupted", e);
@@ -89,14 +99,22 @@ public void onResponse(@NotNull final Call call, @NotNull final Response respons
8999
final BufferedSink bufferedStdout = Okio.buffer(Okio.sink(attachConfig.getStreams().getStdout()));
90100
Thread reader = new Thread(() -> {
91101
try {
102+
log.warn("xxxxx - reader - writeAll -> " + getConnectionProvider().getSource());
92103
bufferedStdout.writeAll(getConnectionProvider().getSource());
104+
log.warn("xxxxx - reader - flush");
93105
bufferedStdout.flush();
106+
log.warn("xxxxx - reader - flushed");
94107
CountDownLatch done = new CountDownLatch(1);
95108
delayed(100, "reader", () -> {
109+
log.warn("xxxxx - reader - delay ...");
96110
attachConfig.onSourceConsumed();
111+
log.warn("xxxxx - reader - delay onSourceConsumed");
97112
return null;
98113
}, done);
99-
done.await(5, TimeUnit.SECONDS);
114+
boolean inTime = done.await(5, TimeUnit.SECONDS);
115+
if (!inTime) {
116+
log.warn("xxxxx - reader - done timeout");
117+
}
100118
}
101119
catch (InterruptedException e) {
102120
log.debug("source->stdout interrupted", e);
@@ -127,8 +145,14 @@ public void run() {
127145
try {
128146
action.get();
129147
}
148+
catch (Exception e) {
149+
log.warn("xxxxx - delayed - error", e);
150+
throw e;
151+
}
130152
finally {
153+
log.warn("xxxxx - delayed - done");
131154
done.countDown();
155+
log.warn("xxxxx - delayed - cancel");
132156
cancel();
133157
}
134158
}

integrationtest/src/test/groovy/de/gesellix/docker/engine/OkDockerClientIntegrationSpec.groovy

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ class OkDockerClientIntegrationSpec extends Specification {
122122
// create container
123123
// docker run --rm -it gesellix/testimage:os-windows cmd /V:ON /C "set /p line= & echo #!line!#"
124124
def containerConfig = [
125-
Tty : true,
126-
OpenStdin: true,
127-
Image : CONSTANTS.imageName,
128-
Cmd : LocalDocker.isNativeWindows()
125+
HostConfig : [
126+
AutoRemove: true
127+
],
128+
AttachStdin : true,
129+
AttachStdout: true,
130+
AttachStderr: true,
131+
Tty : true,
132+
OpenStdin : true,
133+
StdinOnce : true,
134+
Image : CONSTANTS.imageName,
135+
Cmd : LocalDocker.isNativeWindows()
129136
? ["cmd", "/V:ON", "/C", "set /p line= & echo #!line!#"]
130137
: ["/bin/sh", "-c", "read line && echo \"#\$line#\""]
131138
]
@@ -136,10 +143,14 @@ class OkDockerClientIntegrationSpec extends Specification {
136143
// start container
137144
client.post([path : "/containers/${containerId}/start".toString(),
138145
requestContentType: "application/json"])
146+
// resize container TTY
147+
client.post([path : "/containers/${containerId}/attach/resize".toString(),
148+
query: [h: 46, w: 158]])
139149
// inspect container
140150
def multiplexStreams = !client.get([path: "/containers/${containerId}/json".toString()]).content.Config.Tty
141151

142152
def content = "attach ${UUID.randomUUID()}"
153+
println "content (length ${content.length()}): $content"
143154
def expectedOutput = "$content\r\n#$content#\r\n"
144155

145156
def stdout = new ByteArrayOutputStream(expectedOutput.length())
@@ -176,6 +187,7 @@ class OkDockerClientIntegrationSpec extends Specification {
176187

177188
when:
178189
stdin.write("$content\n".bytes)
190+
println "ttttt - written"
179191
stdin.flush()
180192
stdin.close()
181193
def sourceConsumed = onSourceConsumed.await(5, SECONDS)

0 commit comments

Comments
 (0)