Fixed allowing multiple shutdown procedures

- Ghost doesn't prevent itself from running the `shutdown` procedure more than once
- if you spam Ctrl-C, you can reproduce this
  - this might not be the case when running using `yarn dev` because
    some Grunt code captures the SIGINT/SIGTERM, but that is changing
    very soon
- whilst not necessary a problem now, we might introduce code that runs
  during a shutdown but only expects to happen once
- this commit introduces a flag to say that Ghost is shutting down, and
  prevents the `shutdown` function from executing further once true
This commit is contained in:
Daniel Lockyer 2022-08-05 10:48:05 +02:00
parent 949d3e7508
commit 36fef8976b

View File

@ -137,7 +137,14 @@ class GhostServer {
* Called on SIGINT or SIGTERM * Called on SIGINT or SIGTERM
*/ */
async shutdown(code = 0) { async shutdown(code = 0) {
// Prevent this function being run multiple times by checking whether we're
// already shutting down
if (this.isShuttingDown) {
return;
}
try { try {
this.isShuttingDown = true;
logging.warn(tpl(messages.ghostIsShuttingDown)); logging.warn(tpl(messages.ghostIsShuttingDown));
await this.stop(); await this.stop();
setTimeout(() => { setTimeout(() => {