Mercurial > prosody-hg
comparison util/startup.lua @ 12553:cc0ec0277813 0.12
util.startup: Fix async waiting for last shutdown steps
Observed problem: When shutting down prosody would immediately exit
after waiting for s2s connections to close, skipping the last cleanup
events and reporting the exit reason and code.
This happens because prosody.main_thread is in a waiting state and
queuing startup.shutdown is dispatched trough the main loop via
nexttick, but since the main loop was no longer running at that point it
proceeded to the end of the prosody script and exited there.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 14 Jun 2022 16:28:49 +0200 |
| parents | 3ae9299d61d7 |
| children | f0474d40364c |
comparison
equal
deleted
inserted
replaced
| 12549:3729a6bdb562 | 12553:cc0ec0277813 |
|---|---|
| 351 prosody.shutdown_code = code; | 351 prosody.shutdown_code = code; |
| 352 prosody.events.fire_event("server-stopping", { | 352 prosody.events.fire_event("server-stopping", { |
| 353 reason = reason; | 353 reason = reason; |
| 354 code = code; | 354 code = code; |
| 355 }); | 355 }); |
| 356 server.setquitting(true); | 356 prosody.main_thread:run(startup.shutdown); |
| 357 end | 357 end |
| 358 end | 358 end |
| 359 | 359 |
| 360 function startup.load_secondary_libraries() | 360 function startup.load_secondary_libraries() |
| 361 --- Load and initialise core modules | 361 --- Load and initialise core modules |
| 642 prosody.events.fire_event("server-stopped"); | 642 prosody.events.fire_event("server-stopped"); |
| 643 prosody.log("info", "Shutdown complete"); | 643 prosody.log("info", "Shutdown complete"); |
| 644 | 644 |
| 645 prosody.log("debug", "Shutdown reason was: %s", prosody.shutdown_reason or "not specified"); | 645 prosody.log("debug", "Shutdown reason was: %s", prosody.shutdown_reason or "not specified"); |
| 646 prosody.log("debug", "Exiting with status code: %d", prosody.shutdown_code or 0); | 646 prosody.log("debug", "Exiting with status code: %d", prosody.shutdown_code or 0); |
| 647 server.setquitting(true); | |
| 648 end | |
| 649 | |
| 650 function startup.exit() | |
| 647 os.exit(prosody.shutdown_code); | 651 os.exit(prosody.shutdown_code); |
| 648 end | 652 end |
| 649 | 653 |
| 650 -- prosodyctl only | 654 -- prosodyctl only |
| 651 function startup.prosodyctl() | 655 function startup.prosodyctl() |
