Mercurial > prosody-hg
comparison util/startup.lua @ 13452:69faf3552d52
mod_posix: Move POSIX signal handling into util.startup to avoid race
When libunbound is initialized, it spawns a thread to work in.
In case a module initializes libunbound, e.g. by triggering a s2s
connection, Prosody would not handle signals, instead immediately quit
on e.g. the reload (SIGHUP) signal. Likely because the libunbound thread
would not have inherited the signal mask from the main Prosody thread.
Thanks Menel, riau and franck-x for reporting and help narrowing down
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 02 Mar 2024 13:23:24 +0100 |
| parents | 0efb53a0852e |
| children | b0c27628f588 |
comparison
equal
deleted
inserted
replaced
| 13451:4a9a69659727 | 13452:69faf3552d52 |
|---|---|
| 669 for hostname in pairs(config.getconfig()) do | 669 for hostname in pairs(config.getconfig()) do |
| 670 prosody.hosts[hostname] = startup.make_host(hostname); | 670 prosody.hosts[hostname] = startup.make_host(hostname); |
| 671 end | 671 end |
| 672 end | 672 end |
| 673 | 673 |
| 674 function startup.hook_posix_signals() | |
| 675 if prosody.platform ~= "posix" then return end | |
| 676 local have_signal, signal = pcall(require, "prosody.util.signal"); | |
| 677 if not have_signal then | |
| 678 log("warn", "Couldn't load signal library, won't respond to SIGTERM"); | |
| 679 return | |
| 680 end | |
| 681 signal.signal("SIGTERM", function() | |
| 682 log("warn", "Received SIGTERM"); | |
| 683 prosody.main_thread:run(function() | |
| 684 prosody.unlock_globals(); | |
| 685 prosody.shutdown("Received SIGTERM"); | |
| 686 prosody.lock_globals(); | |
| 687 end); | |
| 688 end); | |
| 689 | |
| 690 signal.signal("SIGHUP", function() | |
| 691 log("info", "Received SIGHUP"); | |
| 692 prosody.main_thread:run(function() prosody.reload_config(); end); | |
| 693 -- this also reloads logging | |
| 694 end); | |
| 695 | |
| 696 signal.signal("SIGINT", function() | |
| 697 log("info", "Received SIGINT"); | |
| 698 prosody.main_thread:run(function() | |
| 699 prosody.unlock_globals(); | |
| 700 prosody.shutdown("Received SIGINT"); | |
| 701 prosody.lock_globals(); | |
| 702 end); | |
| 703 end); | |
| 704 | |
| 705 signal.signal("SIGUSR1", function() | |
| 706 log("info", "Received SIGUSR1"); | |
| 707 fire_event("signal/SIGUSR1"); | |
| 708 end); | |
| 709 | |
| 710 signal.signal("SIGUSR2", function() | |
| 711 log("info", "Received SIGUSR2"); | |
| 712 fire_event("signal/SIGUSR2"); | |
| 713 end); | |
| 714 end | |
| 715 | |
| 674 function startup.cleanup() | 716 function startup.cleanup() |
| 675 prosody.log("info", "Shutdown status: Cleaning up"); | 717 prosody.log("info", "Shutdown status: Cleaning up"); |
| 676 prosody.events.fire_event("server-cleanup"); | 718 prosody.events.fire_event("server-cleanup"); |
| 677 end | 719 end |
| 678 | 720 |
| 746 startup.init_promise(); | 788 startup.init_promise(); |
| 747 startup.init_async(); | 789 startup.init_async(); |
| 748 startup.init_http_client(); | 790 startup.init_http_client(); |
| 749 startup.init_data_store(); | 791 startup.init_data_store(); |
| 750 startup.init_global_protection(); | 792 startup.init_global_protection(); |
| 793 startup.hook_posix_signals(); | |
| 751 startup.prepare_to_start(); | 794 startup.prepare_to_start(); |
| 752 startup.notify_started(); | 795 startup.notify_started(); |
| 753 end | 796 end |
| 754 | 797 |
| 755 return startup; | 798 return startup; |
