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

fixes 1492: tty initial size error #1529

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

lifubang
Copy link
Contributor

@lifubang lifubang commented Nov 21, 2018

Signed-off-by: Lifubang lifubang@acmcoder.com

fixes #1492.

For Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64), Docker version 17.12.0-ce, build c97c6d6 / 18.03.0-ce, build 0520e24
When I run: docker exec -it ubuntu /bin/bash
The tty's size is small than window's size.

root@iZ2zeesy3n96esegm7tue0Z:~# docker exec -it ubuntu /bin/bash
root@97b3e229a701:/# ls -a
.   .dockerenv  bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
..  .r          boot  etc  lib   media  opt  root  sbin  sys  usr

After I fix the bug:

root@iZ2zeesy3n96esegm7tue0Z:~# ./docker-linux-amd64 exec -it ubuntu /bin/bash
root@97b3e229a701:/# ls -a
.  ..  .dockerenv  .r  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

If not fix this bug, it's too inconvenient for me to use docker exec -it.

- What I did

  1. Fix tty initial size error
    I think it's a bug of dockerd, but for previous dockerd edition, I think we can fix it in cli.
  2. Fix when we use --debug flag, the first shell prompt don't return to the head of line when we got an error in func resizeTtyTo!

- How I did it
func MonitorTtySize in file cli/command/container/tty.go
I move the call resizeTty() to last and run it asynchronously.

  1. Because in sometimes when dockercli call tty resize, the exec have not finished yet. Then we got a message "Error response from daemon: no such exec", but we ignore it, so we need to throw this error and deal with it after 10 milliseconds.
  2. Add \r when logrus.Debugf.

- How to verify it
It's convenient for me to use docker exec -it.
I don't need to resize the window.

- Description for the changelog
fixes tty initial size error

- I have no more cute animal now
Before fix:
vim /etc/mime.types
sk j _1irw za2kc78iody5

After fix:
vim /etc/mime.types
x z0 r5jg_i4h x6m2bny 4

@codecov-io
Copy link

codecov-io commented Nov 21, 2018

Codecov Report

Merging #1529 into master will decrease coverage by 0.77%.
The diff coverage is 50%.

@@            Coverage Diff             @@
##           master    #1529      +/-   ##
==========================================
- Coverage   56.07%   55.29%   -0.78%     
==========================================
  Files         306      289      -17     
  Lines       20950    19388    -1562     
==========================================
- Hits        11747    10721    -1026     
+ Misses       8354     7968     -386     
+ Partials      849      699     -150

@lifubang
Copy link
Contributor Author

@thaJeztah it is the duplicate copy of #1380, PTAL.

@@ -34,19 +34,48 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for adding \r here?

Copy link
Contributor Author

@lifubang lifubang Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolyshkin Nice to see you again ^_^
Thanks for your review. It's because that:

root@iZ2zeesy3n96esegm7tue0Z:~# docker --debug exec -it k8s_nginxgateway_apigateway-p46ch_default_2de895e0-e8a8-11e8-badf-00163e0af11c_0 /bin/bash
DEBU[0000] Error resize: Error response from daemon: no such exec 
                                                                  root@apigateway-p46ch:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  t    usr
boot  etc  lib   media  opt  root  sbin  sys  tmp  var
root@apigateway-p46ch:/#

When we use --debug, the first shell prompt don't return to the head of line!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I've definitely seen it in the past.

Maybe add a comment why \r is there to the patch description, so anyone doing git blame can find the reason why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No code change, modify patch description now. Thanks.

@lifubang lifubang force-pushed the ttyexecresize branch 2 times, most recently from a3a34a1 to c2205f7 Compare November 21, 2018 23:06
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, noticed I had some comments pending that I didn't post yet.

Still have to do a full review though (and I see some comments were still pending?)

inspectFunc func(string) (types.ContainerJSON, error)
execInspectFunc func(execID string) (types.ContainerExecInspect, error)
execCreateFunc func(container string, config types.ExecConfig) (types.IDResponse, error)
createContainerFunc func(config *container.Config,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this signature did not change; perhaps you can revert this formatting change to keep the change focussed on the actual changes? Or did gofmt force this wrap?

Copy link
Contributor Author

@lifubang lifubang Feb 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in circleci:lint, there is an error:
cli/command/container/client_test.go:18::warning: line is 201 characters (lll),
so I need to force this wrap, or else ci will get an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! hm that's a pity (as it's not related to this change 😞)


resizeTty()
// safeResizeTty is to resize the tty's size safely
func safeResizeTty(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safeResizeTty is a bit confusing for a name. Perhaps retryResizeTTY (but I'm open to better suggestions)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I change it to initTtySize, because this function is used to init the tty's size.

}
err := rttyFunc(ctx, cli, id, isExec)
if err != nil {
retryTimes := 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop looked a bit complicated to me; wondering; would this work? (pls double-check; it's just a very quick draft)

go func() {
	var err error
	for retry := 0; retry < 5; retry++ {
		time.Sleep(10 * time.Millisecond)
		err = rttyFunc(ctx, cli, id, isExec)
		if err == nil {
			break
		}
	}
	if err != nil {
		fmt.Fprintln(cli.Err(), "Resize tty error, we'll use a default size. You can resize the tty size manually.")
	}
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations, this quick draft works very well.

@lifubang lifubang force-pushed the ttyexecresize branch 3 times, most recently from 6076ddd to 37f0d7c Compare February 11, 2019 08:08
var err error
for retry := 0; retry < 5; retry++ {
time.Sleep(10 * time.Millisecond)
err = rttyFunc(ctx, cli, id, isExec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

if err = rttyFunc(ctx, cli, id, isExec); err == nil{
    break
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I also changed the line 54:

if err := rttyFunc(ctx, cli, id, isExec); err != nil {

}
}
if err != nil {
fmt.Fprintln(cli.Err(), "Resize tty error, we'll use a default size. You can resize the tty size manually.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fmt.Println(cli.Err(), "error resizing tty, falling back to default size") ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, good suggestion; perhaps "failed to" or "unable to" (I think we generally use failed to for such things)

Suggested change
fmt.Fprintln(cli.Err(), "Resize tty error, we'll use a default size. You can resize the tty size manually.")
fmt.Fprintln(cli.Err(), "failed to resize tty, using default size")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I can't use commit suggestion button in this conversation because I also need to update the test case.

Signed-off-by: Lifubang <lifubang@acmcoder.com>
Signed-off-by: lifubang <lifubang@acmcoder.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @lifubang 👍 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

initial windows size of docker exec -it is too small
6 participants