gajus / lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
Other
517 stars 33 forks source link

Would it be better to wait for the server close event instead of a fixed time? #15

Closed zhaoyao91 closed 4 years ago

zhaoyao91 commented 4 years ago

In the README, I noticed it suggest wait some time before calling server.close(). According to the node.js doc, could the following code snippet be better? Or is there some other consideration?

lightship.registerShutdownHandler(() => {
  return new Promise((resolve, reject) => {
    server.close(err => {
      if (err) reject(err);
      else resolve();
    });
  });
});
gajus commented 4 years ago

Don't do that – you will kill active requests.

See:

gajus commented 4 years ago

Sorry, you won't kill active requests in this case. However, it is possible that the server might still receive requests after receiving the SIGKILL, i.e. you need to allow time to ensure that no more traffic is being routed to your pod instance.

See:

zhaoyao91 commented 4 years ago

Seems that the delay is a magic number since we don't know how many time it will take to switch iptables.

gajus commented 4 years ago

That is correct.