Repository navigation
Conversation
There was a problem hiding this comment.
If our "pid 1" can't receive any signals, why even bother with this signal proxying?
There was a problem hiding this comment.
Well, this is the trick, it does receive the signals when it has a child. Maybe if we put the child in its own sid this won't be necessary?
There was a problem hiding this comment.
Hrm, indeed - that sounds more like an issue related to our syscall.Exec madness than to being "pid 1" to me, but I'm only spit-balling of course. Processes and signals are tricky, and namespaces only make them more so. :)
There was a problem hiding this comment.
It is indeed likely. It would be interesting to see the internals for signal handling. It is possible that the Go runtime catches all signal before 'giving' them to the process. If so, then yes, the Exec would override the go's internal signal handling without restoring ISIG.
|
I see multiple tests failures. |
|
An the tests seems to never finish |
|
@vieux, Try again, it appens some time, but it is not linked to the PR. It just make the race a bit more obvious. |
|
LGTM |
|
+1. Tested SIGSTP and SIGINT. This makes working on containers in the foreground much easier. |
|
Do you think this might help with #2878? If so, I can test it tomorrow for you. |
|
FYI I did something very similar in my long-running dockerinit branch. Also, if dockerinit is pid 1 then it will be responsible for reaping zombies, otherwise you can get a lot of defunct processes in the container. See jpoimboe/docker@affa9a0. |
|
thx @jpoimboe |
|
I would like to avoid running the application as pid!=1 if possible, because it breaks "docker run /sbin/init" and forces us to make a special case. I don't like this "-fork" flag, what's the point of it for the user? On Thu, Dec 19, 2013 at 11:59 PM, Guillaume J. Charmes
|
|
The only motivation behing the |
|
Ok. So if we make it so pid==1 there's no more need for that flag. Can't we simply exec() without forking? On Fri, Dec 20, 2013 at 7:46 AM, Guillaume J. Charmes
|
|
Well, this was a suggestion on how to fix the signal issue. I can try to find an other one. |
|
From a Linux kernel standpoint, pid 1 (whether real or namespaced) will see a SIGTERM, so it can register a SIGTERM handler if it wants. However, pid 1 also has flag SIGNAL_UNKILLABLE which means that a SIGTERM won't kill it, even if the signal came from the parent namespace. So if dockerinit execs the app as pid 1, there's no way to kill it with a SIGTERM, unless the app happens to have its own SIGTERM handler (which would be unusual). |
|
BTW an alternative to the "-fork" flag would be to only exec if the app name is "/sbin/init" or "systemd", which is what I did in my long-running dockerinit branch. |
|
I see the problem now. I didn't realize the rules for signals to pid=1 applied to namespaced processes too, but it makes sense. Is there any way for the app to inherit handlers setup by dockerinit before exec? As I write this it seems highly doubtful (where would the handlers even live in memory after exec?) but worth asking :) By the way this is the first sensible argument I've seen in favor of long-running init. On Fri, Dec 20, 2013 at 9:06 AM, Josh Poimboeuf [email protected]
|
|
No, all signal handlers are wiped out by exec. I hadn't known about this issue before, but yeah this definitely adds to the argument for a long-running dockerinit. |
|
@shykes I'll make some test with "raw" signal handling in CGO to see if I can manage something. However, as you mentioned it is doubtful. |
|
From "man 2 execve": |
|
thanks @jpoimboe for the infos. |
|
On Fri, Dec 20, 2013 at 10:04 AM, Guillaume J. Charmes <
My understanding is that you're talking about a limitation in the language |
|
@creack don't waste your time for the signal thing, this seems pretty On Fri, Dec 20, 2013 at 11:34 AM, Solomon Hykes [email protected] wrote:
|
|
@shykes indeed, that's why I say 'without forking os/exec' in the sense of code fork. We'd need to reimplement a lot from it in order to do this. |
|
ping @creack can we close this? |
|
I'm not really sure what the fix is other than the proposed init process, but I think this needs a fix. My current use case is that I'm trying to run a docker registry under foreman for development purposes. I can't seem to figure out any way to get the registry to shutdown when I ctrl-c docker without an explicit 'docker stop' after. That is, nothing short of modifying the docker image to wrap everything in something that responds to SIGTERM. It's not super hard, something like 'CMD trap exit TERM; & wait' works, but that's not terribly user friendly. |
|
Why is this closed? It doesn't appear to be fixed. |
|
@anacrolix This is a pull request. Issues are tracked separately. See #3793 |
|
why this PR is not accepted yet? we need a definitive way to solve it |
|
Hello, i have this problem with SIGTERM.... |
|
If you're apps aren't receiving signals, it's probably because the app has been inited improperly OR it drops default signal handlers when run as PID 1. |
|
My solution for the PID1 problem: The Dockerfile ends with: Than I run with this shell script, which has the filename of The trick is So Here is my Dockerised Node.js development environment: https://github.com/DJviolin/Node.js-Development-Environment |
|
@rafaelcapucho This problem still seems to exist in current Mesos versions, together with Docker 1.8 IMHO... Is there any suggested fix/workaround? |
The previous upstart method did not stop containers when the upstart service was stopped. This is a result of moby/moby#3240 As a workaround for the issue, on start we write the container ID to a file, and then use a post-stop script to kill that container.
The issue is that we can't kill pid 1. By default, now dockerinit forkexec instead of exec. Resulting in the process started to be pid 2.
The previous behavior is still available via the '-fork' option of
docker run.Note that disabling fork will result in uninterruptible process.
I also noticed that this PR make some races within the test more obvious. I'll work on it, but it is a separate issue.