erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
697 stars 232 forks source link

SIGTERM not caught in docker container using foreground (OTP 19.3) #584

Closed macpie closed 6 years ago

macpie commented 7 years ago

Since OPT 19.3

erts: A received SIGTERM signal to beam will generate a 'stop' message to the init process and terminate the Erlang VM nicely. This is equivalent to calling init:stop/0.

So I wanted to pair that with docker stop command to get a proper stop for my application.

docker stop

The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL.

It is recommended to use foreground with docker, problem is, it does not seems to catch the SIGTERM. I then realized that foreground is using the +Bd flag. Which seems to interfere with the ability to catch the SIGTERM.

Option d (same as specifying +B without an extra option) disables the break handler. Option i makes the emulator ignore any break signal.

Does foreground really need that flag? Should there be an extra command for this case?

PS: I fixed this by using console and flags _build/default/rel/app/bin/legacy console -noshell -noinput which I find acceptable. The only difference, that I could find, between console and foreground are those 3 flags -noshell -noinput +Bd

tsloughter commented 7 years ago

Ah, crap! We did add that :(. Ugh, now I wish we hadn't. It wasn't an issue when Erlang didn't respect SIGTERM...

Going to have to mull this over.

macpie commented 7 years ago

Yes OTP catching SIGTERM is nice. Nevertheless doing console -noshell -noinput is ok for me.

Thanks for looking!

tsloughter commented 7 years ago

Hm, looks like this could be fixed in 19.3.2:

OTP-14358 Application(s): erts Related Id(s): OTP-14085

            The +Bi command line argument of erl erroneously caused
            SIGTERM to be ignored by the VM as well as of all its
            child processes. This bug was introduced in erts
            version 8.3.
macpie commented 7 years ago

@tsloughter sweet will give it a try

macpie commented 6 years ago

fixed indeed