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

Fix panic of "docker stats --format {{.Name}} --all" #30776

Merged
merged 1 commit into from
Feb 8, 2017

Conversation

WeiZhang555
Copy link
Contributor

This commit fixes panic when execute stats command:

  • use --format {{.Name}} with --all when there're exited containers.
  • use --format {{.Name}} while stating exited container.

The root cause is when stating an exited container, the result from the
api didn't contain the Name and ID field, which will make format
process panic.

Panic log is like this:

panic: runtime error: slice bounds out of range [recovered]
	panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0xb20f80, 0xc420014110)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
text/template.errRecover(0xc4201773e8)
	/usr/local/go/src/text/template/exec.go:140 +0x2ad
panic(0xb20f80, 0xc420014110)
	/usr/local/go/src/runtime/panic.go:458 +0x243
github.com/docker/docker/cli/command/formatter.(*containerStatsContext).Name(0xc420430160,
0x0, 0x0)
	/go/src/github.com/docker/docker/cli/command/formatter/stats.go:148
+0x86
reflect.Value.call(0xb9a3a0, 0xc420430160, 0x2213, 0xbe3657, 0x4,
0x11bc9f8, 0x0, 0x0, 0x4d75b3, 0x1198940, ...)
	/usr/local/go/src/reflect/value.go:434 +0x5c8
reflect.Value.Call(0xb9a3a0, 0xc420430160, 0x2213, 0x11bc9f8, 0x0, 0x0,
0xc420424028, 0xb, 0xb)
	/usr/local/go/src/reflect/value.go:302 +0xa4
text/template.(*state).evalCall(0xc420177368, 0xb9a3a0, 0xc420430160,
0x16, 0xb9a3a0, 0xc420430160, 0x2213, 0x1178fa0, 0xc4203ea330,
0xc4203de283, ...)
	/usr/local/go/src/text/template/exec.go:658 +0x530

Signed-off-by: Zhang Wei [email protected]

This is part of #29702, here is the client fix, daemon fix is still under discussion.

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

LGTM

@LK4D4
Copy link
Contributor

LK4D4 commented Feb 7, 2017

@WeiZhang555 I believe there was some tests in old PR as well :)

This commit fixes panic when execute stats command:

* use --format {{.Name}} with --all when there're exited containers.
* use --format {{.Name}} while stating exited container.

The root cause is when stating an exited container, the result from the
api didn't contain the Name and ID field, which will make format
process panic.

Panic log is like this:

```
panic: runtime error: slice bounds out of range [recovered]
	panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0xb20f80, 0xc420014110)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
text/template.errRecover(0xc4201773e8)
	/usr/local/go/src/text/template/exec.go:140 +0x2ad
panic(0xb20f80, 0xc420014110)
	/usr/local/go/src/runtime/panic.go:458 +0x243
github.com/docker/docker/cli/command/formatter.(*containerStatsContext).Name(0xc420430160,
0x0, 0x0)
	/go/src/github.com/docker/docker/cli/command/formatter/stats.go:148
+0x86
reflect.Value.call(0xb9a3a0, 0xc420430160, 0x2213, 0xbe3657, 0x4,
0x11bc9f8, 0x0, 0x0, 0x4d75b3, 0x1198940, ...)
	/usr/local/go/src/reflect/value.go:434 +0x5c8
reflect.Value.Call(0xb9a3a0, 0xc420430160, 0x2213, 0x11bc9f8, 0x0, 0x0,
0xc420424028, 0xb, 0xb)
	/usr/local/go/src/reflect/value.go:302 +0xa4
text/template.(*state).evalCall(0xc420177368, 0xb9a3a0, 0xc420430160,
0x16, 0xb9a3a0, 0xc420430160, 0x2213, 0x1178fa0, 0xc4203ea330,
0xc4203de283, ...)
	/usr/local/go/src/text/template/exec.go:658 +0x530
```

Signed-off-by: Zhang Wei <[email protected]>
@WeiZhang555 WeiZhang555 force-pushed the stats-all-format-name-panic-cli branch from 741cab3 to 5a7b3c7 Compare February 8, 2017 02:27
@WeiZhang555
Copy link
Contributor Author

@LK4D4 adding an unit test, the other integration test depend on daemon side fix so I didn't move it here. :-)

@LK4D4
Copy link
Contributor

LK4D4 commented Feb 8, 2017

@WeiZhang555 thanks!
LGTM

@LK4D4 LK4D4 merged commit f5116c6 into moby:master Feb 8, 2017
@GordonTheTurtle GordonTheTurtle added this to the 1.14.0 milestone Feb 8, 2017
@WeiZhang555 WeiZhang555 deleted the stats-all-format-name-panic-cli branch February 9, 2017 01:34
@thaJeztah thaJeztah mentioned this pull request Feb 18, 2017
@thaJeztah thaJeztah modified the milestones: 17.03.0, 17.04.0 Feb 18, 2017
thaJeztah pushed a commit to thaJeztah/docker that referenced this pull request Feb 18, 2017
…panic-cli

Fix panic of "docker stats --format {{.Name}} --all"
(cherry picked from commit f5116c6)

Signed-off-by: Sebastiaan van Stijn <[email protected]>
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
…panic-cli

Fix panic of "docker stats --format {{.Name}} --all"
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.

5 participants