Skip to content

Conversation

@psyeugenic
Copy link
Contributor

@psyeugenic psyeugenic commented Jan 23, 2017

In todays Erlang runtime system OS signals cannot be handled by an Erlang developer. Some signals are used internally by erts, for instance

  • SIGUSR1 is used to generate crashdumps,
  • SIGUSR2 is used to halt threads in a crashdump,
  • SIGQUIT is used to halt Erlang immediately,
  • SIGINT is used for a break-handler which is only intended to be used for debugging and
  • SIGTERM (from 19.3) will halt Erlang via init:stop/0.

With this PR a gen_event server, erl_signal_server, is started to handle enabled signals from the operating system. A default handler is installed to mimic the previous behavior of above signals except for SIGINT. The break-handler still uses SIGINT internally.

Subscribable signals with this PR are: SIGHUP, SIGILL, SIGABRT, SIGALRM, SIGTERM, SIGQUIT, SIGUSR1, SIGUSR2, SIGCHLD, SIGSTOP, SIGTSTP.

Signals can be enabled with erts_internal:set_signal(Signal, Option), where Signal is any subscribable signal, i.e. sighup or sigusr1, and Option is one of handle, ignore or default. By setting handle for a signal it means that a notification will be sent to erl_signal_server once that signal has been received from the OS.

Names are up for debate of course. As is the usability of this feature. SIGTERM and SIGHUP was the initial driving force for this.

* and some minor refactoring
A received SIGHUP signal to beam will generate a '{notify, sighup}' message
to the registered process 'erl_signal_server'. 'erl_signal_server' is a
gen_event process.
@bjorng
Copy link
Contributor

bjorng commented Jan 23, 2017

I don't think that it should be allowed to handle SIGILL. There is no way to predict the state of the run-time system after executing an illegal instruction. Attempting to handle may do more harm than good, and could make it harder to find the original problem.

Not sure about SIGCHLD either. Couldn't handling it interfere with open_port({spawn,...}, ...) or cause zombie processes?

@bjorng bjorng added feature team:VM Assigned to OTP team VM labels Jan 23, 2017
@psyeugenic
Copy link
Contributor Author

@bjorng I agree that SIGILL may not be that useful however SIGCHLD may be useful in some instances. It could perhaps be useful when running beam as PID 1 to mitigate the zombie problem. At least there would be a way to handle SIGCHLD signals. There is no interference with port programs today since those SIGCHLDs are sent to the forker process and not the beam process. I can't see that we have a zombie problem there. Also, in the testcase os_signal_SUITE:t_sigchld_fork/1 we test for fork() and waitpid(). No zombies - in that testcase either.

Once again, I agree that SIGILL should probably be removed. Are there any other modifications to the signal whitelist that should be done?

@psyeugenic psyeugenic self-assigned this Jan 23, 2017
@psyeugenic psyeugenic force-pushed the egil/20/erts/signal-service branch 2 times, most recently from a143b02 to d8eede9 Compare January 24, 2017 15:06
@psyeugenic
Copy link
Contributor Author

Changed module from erts_internal to os since it's more appropriate.

There is a coupling here that needs to be reconsidered. If a signal is set to be handled it will always send notifications to erl_signal_server. Viewing the kernel application as a part of the runtime this would be fine but I think I would rather decouple this an additional step.

@mikpe
Copy link
Contributor

mikpe commented Jan 25, 2017

For Erlang code it only makes sense to allow asynchronous signals to be handled. Synchronous ones corresponding to hardware traps (SIGILL, SIGBUS, SIGSEGV, SIGFPE) should be excluded.

@psyeugenic psyeugenic force-pushed the egil/20/erts/signal-service branch from d8eede9 to a62ef9a Compare February 2, 2017 11:21
@skull-squadron
Copy link

skull-squadron commented Apr 6, 2017

PrajaktaPurohit added a commit to chef/chef-server that referenced this pull request Oct 23, 2019
Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 24, 2019
Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 24, 2019
Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 24, 2019
Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 25, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 26, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Oct 31, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 1, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 4, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 7, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 7, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 12, 2019
send notification for erl_signal_server on sigterm sent from runit

Runit sends sigterm to the erlang application. Erlang 19.3 onwards
erlang can be notified of some of the os signals.
REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 13, 2019
Changes to SIGTERM handling in Erlang 19.x caused runit failures in
Chef Server. This was originally fixed when we upgraded to Erlang 19
by passing a startup flag to the Erlang VM on bootup.  But the startup
flag was removed in Erlang 20, so another fix had to be employed.

This change effectively reverts Erlang's SIGTERM handling to previous
(pre-19) behavior.

REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
lbakerchef added a commit to chef/chef-server that referenced this pull request Nov 14, 2019
Changes to SIGTERM handling in Erlang 19.x caused runit failures in
Chef Server. This was originally fixed when we upgraded to Erlang 19
by passing a startup flag to the Erlang VM on bootup.  But the startup
flag was removed in Erlang 20, so another fix had to be employed.

This change effectively reverts Erlang's SIGTERM handling to previous
(pre-19) behavior.

REF: erlang/otp#1315

Signed-off-by: Lincoln Baker <lbaker@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants