ensure logstash terminates on second sigint

As more java code is being used in logstash, it's likely that
java.lang.Threads which aren't set as daemon may be running when
`exit(1)` is called.

Because System.exit only raises a SystemExit exception, it's possible
that threads will continue to execute, and if they're not set as daemon
then the JVM won't terminate.

By calling `System.exit!` instead we ensure jruby calls the underlying
java.lang.System.exit and logstash terminates immediately.

Fixes #8729
This commit is contained in:
Joao Duarte 2017-11-27 10:20:52 +00:00 committed by João Duarte
parent 1ae3a5ea43
commit 7537412cda

View file

@ -484,7 +484,10 @@ class LogStash::Runner < Clamp::StrictCommand
Stud::trap("INT") do
if @interrupted_once
logger.fatal(I18n.t("logstash.agent.forced_sigint"))
exit(1)
# calling just Kernel.exit only raises SystemExit exception
# and doesn't guarantee the process will terminate
# We must call Kernel.exit! so java.lang.System.exit is called
exit!(1)
else
logger.warn(I18n.t("logstash.agent.sigint"))
Thread.new(logger) {|lg| sleep 5; lg.warn(I18n.t("logstash.agent.slow_shutdown")) }