From 63a773bc2f2e2bb8685a9f03a596dc000bf54e55 Mon Sep 17 00:00:00 2001 From: Lifubang Date: Wed, 19 Sep 2018 14:46:32 +0800 Subject: [PATCH] fixes tty size error Signed-off-by: Lifubang code optimization Signed-off-by: Lifubang fixes no such exec error when tty resize Signed-off-by: Lifubang --- cli/command/container/tty.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cli/command/container/tty.go b/cli/command/container/tty.go index cb49ded8ef4f..deb511517231 100644 --- a/cli/command/container/tty.go +++ b/cli/command/container/tty.go @@ -16,9 +16,9 @@ import ( ) // resizeTtyTo resizes tty to specific height and width -func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) { +func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error { if height == 0 && width == 0 { - return + return nil } options := types.ResizeOptions{ @@ -34,18 +34,35 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin } if err != nil { - logrus.Debugf("Error resize: %s", err) + logrus.Debugf("Error resize: %s\r", err) } + return err } // MonitorTtySize updates the container tty size when the terminal tty changes size func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error { - resizeTty := func() { + resizeTty := func() error { height, width := cli.Out().GetTtySize() - resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) + return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) } - resizeTty() + err := resizeTty() + if err != nil { + retryTimes := 5 + retry := 0 + go func() { + for { + time.Sleep(10 * time.Millisecond) + err = resizeTty() + if err != nil && retry < retryTimes { + retry++ + logrus.Debugf("Resize tty has retried %d times now\r", retry) + continue + } + break + } + }() + } if runtime.GOOS == "windows" { go func() {