-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
Codecov Report
@@ 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 |
@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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a3a34a1
to
c2205f7
Compare
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😞)
cli/command/container/tty.go
Outdated
|
||
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) { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
cli/command/container/tty.go
Outdated
} | ||
err := rttyFunc(ctx, cli, id, isExec) | ||
if err != nil { | ||
retryTimes := 5 |
There was a problem hiding this comment.
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.")
}
}()
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6076ddd
to
37f0d7c
Compare
cli/command/container/tty.go
Outdated
var err error | ||
for retry := 0; retry < 5; retry++ { | ||
time.Sleep(10 * time.Millisecond) | ||
err = rttyFunc(ctx, cli, id, isExec) |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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:
cli/cli/command/container/tty.go
Line 54 in 5017d5f
if err := rttyFunc(ctx, cli, id, isExec); err != nil { |
37f0d7c
to
5017d5f
Compare
cli/command/container/tty.go
Outdated
} | ||
} | ||
if err != nil { | ||
fmt.Fprintln(cli.Err(), "Resize tty error, we'll use a default size. You can resize the tty size manually.") |
There was a problem hiding this comment.
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")
?
There was a problem hiding this comment.
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)
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") |
There was a problem hiding this comment.
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>
5017d5f
to
3fbffc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this 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 👍 !
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.
After I fix the bug:
If not fix this bug, it's too inconvenient for me to use docker exec -it.
- What I did
I think it's a bug of dockerd, but for previous dockerd edition, I think we can fix it in cli.
- How I did it
func MonitorTtySize in file cli/command/container/tty.goI move the call resizeTty() to last and run it asynchronously.\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
After fix:
vim /etc/mime.types