X Tutup
Skip to content

Fix #30311: dockerd leaks ExecIds on failed exec -i#30340

Merged
AkihiroSuda merged 1 commit intomoby:masterfrom
ijrandom:master
Feb 14, 2017
Merged

Fix #30311: dockerd leaks ExecIds on failed exec -i#30340
AkihiroSuda merged 1 commit intomoby:masterfrom
ijrandom:master

Conversation

@ijrandom
Copy link
Contributor

If libcontainerd failed to start process there will be no callback about "exec done" so cleanup code should be added to ContainerExecStart
Signed-off-by: Dmitry Shyshkin dmitry@shyshkin.org.ua

- What I did
Close streams and removed ExecConfig from container in case of process failed to start
- How I did it
Copy part of cleanup code from containerd exec callback
- How to verify it

  1. execute docker exec -i anycontainer invalidcommand
  2. check for ExecIDs. docker inspect anycontainer | grep -A 10 ExecIDs

- Description for the changelog
Fix #30311: dockerd leaks ExecIds on failed exec -i

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.

Can you please add an automated test?

daemon/exec.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Probably no need to move these lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's necessary to use c in defer

@ijrandom
Copy link
Contributor Author

added tests

@ijrandom
Copy link
Contributor Author

On windows docker exec invalidcommand produce 500 and on linux 404. Which one need to be corrected?

@justincormack
Copy link
Contributor

justincormack commented Jan 22, 2017 via email

Copy link
Contributor

@LK4D4 LK4D4 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 Jan 30, 2017

ping @docker/core-engine-maintainers

Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid expanding this "guess the status code" system further and return a specific http error instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dnephin can you explain a little bit more for @ijrandom ?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I'd be happy to.

This code that you've added to is trying to guess which http status code to return based on an error message string. Instead of guessing based on string matching, we'd like to be explicit about the error.

The explicit error is in api/errors/errors.go NewRequestNotFoundError(). Could you return that directly from the function that causes this error, instead of adding a new string to this list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be clear. You want to return NewRequestNotFoundError from platform specific wrapper to execv/CreateProcess?

Copy link
Member

Choose a reason for hiding this comment

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

Where is the error which contains the text "cannot find"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It come from the windows os when CreateProcess failed

Copy link
Member

Choose a reason for hiding this comment

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

Ok, is there an issue about this? I don't think we return a 404 on other platforms when the path to a binary is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on linux message contains "not found" those producing 404

daemon/exec.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this needs to be protected by the lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only if changes to ec.Running and ec.ExitCode need to be atomic. There were no lock protection in containerd callback - so I added no lock here. Should I add the lock? Add the lock in containerd callback as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. There was a lock. Added lock/unlock and changed message

daemon/exec.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add some context? e.g. "failed to cleanup exec %s streams: %s"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, also changed message in monitor.go

Copy link
Contributor

@mlaventure mlaventure 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 3, 2017

@ijrandom would you mind to fix @dnephin suggestion? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

you can use inspectFieldJSON (https://github.com/docker/docker/blob/master/integration-cli/docker_utils_test.go#L554) instead.

The fix LGTM.

It's better to squash your commits :)

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

Let's makes sure to squash to 1 commit

Signed-off-by: Dmitry Shyshkin <dmitry@shyshkin.org.ua>
@ijrandom
Copy link
Contributor Author

rebased and squashed

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@AkihiroSuda AkihiroSuda merged commit eac68db into moby:master Feb 14, 2017
@GordonTheTurtle GordonTheTurtle added this to the 1.14.0 milestone Feb 14, 2017
liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
upstream issue: moby#30311
Cherry-pick from moby#30340
fix moby#161

Signed-off-by: Dmitry Shyshkin <dmitry@shyshkin.org.ua>
Signed-off-by: Lei Jitang <leijitang@huawei.com>
liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
Fix docker leaks ExecIds on failed exec -i

upstream issue: moby#30311
Cherry-pick from moby#30340
fix moby#161

Signed-off-by: Dmitry Shyshkin <dmitry@shyshkin.org.ua>
Signed-off-by: Lei Jitang <leijitang@huawei.com>


See merge request docker/docker!275
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.

X Tutup