Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] add logs to debug /attach on windows #27

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -51,21 +51,31 @@ public void onResponse(@NotNull final Call call, @NotNull final Response respons
Thread writer = new Thread(() -> {
try {
final BufferedSink bufferedSink = Okio.buffer(getConnectionProvider().getSink());
bufferedSink.writeAll(stdinSource);
long written = bufferedSink.writeAll(stdinSource);
log.warn("xxxxx - writer - written " + written);
bufferedSink.flush();
log.warn("xxxxx - writer - flushed");
attachConfig.onSinkWritten(response);
log.warn("xxxxx - writer - onSinkWritten");
CountDownLatch done = new CountDownLatch(1);
delayed(100, "writer", () -> {
log.warn("xxxxx - writer - delayed");
try {
bufferedSink.close();
log.warn("xxxxx - writer - delayed closed");
attachConfig.onSinkClosed(response);
log.warn("xxxxx - writer - delayed onSinkClosed");
}
catch (Exception e) {
log.warn("error", e);
}
log.warn("xxxxx - writer - delayed return");
return null;
}, done);
done.await(5, TimeUnit.SECONDS);
boolean inTime = done.await(5, TimeUnit.SECONDS);
if (!inTime) {
log.warn("xxxxx - writer - done timeout");
}
}
catch (InterruptedException e) {
log.debug("stdin->sink interrupted", e);
Expand All @@ -89,14 +99,22 @@ public void onResponse(@NotNull final Call call, @NotNull final Response respons
final BufferedSink bufferedStdout = Okio.buffer(Okio.sink(attachConfig.getStreams().getStdout()));
Thread reader = new Thread(() -> {
try {
log.warn("xxxxx - reader - writeAll -> " + getConnectionProvider().getSource());
bufferedStdout.writeAll(getConnectionProvider().getSource());
log.warn("xxxxx - reader - flush");
bufferedStdout.flush();
log.warn("xxxxx - reader - flushed");
CountDownLatch done = new CountDownLatch(1);
delayed(100, "reader", () -> {
log.warn("xxxxx - reader - delay ...");
attachConfig.onSourceConsumed();
log.warn("xxxxx - reader - delay onSourceConsumed");
return null;
}, done);
done.await(5, TimeUnit.SECONDS);
boolean inTime = done.await(5, TimeUnit.SECONDS);
if (!inTime) {
log.warn("xxxxx - reader - done timeout");
}
}
catch (InterruptedException e) {
log.debug("source->stdout interrupted", e);
Expand Down Expand Up @@ -127,8 +145,14 @@ public void run() {
try {
action.get();
}
catch (Exception e) {
log.warn("xxxxx - delayed - error", e);
throw e;
}
finally {
log.warn("xxxxx - delayed - done");
done.countDown();
log.warn("xxxxx - delayed - cancel");
cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,17 @@ class OkDockerClientIntegrationSpec extends Specification {
// create container
// docker run --rm -it gesellix/testimage:os-windows cmd /V:ON /C "set /p line= & echo #!line!#"
def containerConfig = [
Tty : true,
OpenStdin: true,
Image : CONSTANTS.imageName,
Cmd : LocalDocker.isNativeWindows()
HostConfig : [
AutoRemove: true
],
AttachStdin : true,
AttachStdout: true,
AttachStderr: true,
Tty : true,
OpenStdin : true,
StdinOnce : true,
Image : CONSTANTS.imageName,
Cmd : LocalDocker.isNativeWindows()
? ["cmd", "/V:ON", "/C", "set /p line= & echo #!line!#"]
: ["/bin/sh", "-c", "read line && echo \"#\$line#\""]
]
Expand All @@ -136,10 +143,14 @@ class OkDockerClientIntegrationSpec extends Specification {
// start container
client.post([path : "/containers/${containerId}/start".toString(),
requestContentType: "application/json"])
// resize container TTY
client.post([path : "/containers/${containerId}/attach/resize".toString(),
query: [h: 46, w: 158]])
// inspect container
def multiplexStreams = !client.get([path: "/containers/${containerId}/json".toString()]).content.Config.Tty

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

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

when:
stdin.write("$content\n".bytes)
println "ttttt - written"
stdin.flush()
stdin.close()
def sourceConsumed = onSourceConsumed.await(5, SECONDS)
Expand Down