Skip to content

Feedback before writing: Shutdown gracefully #705

@goldbergyoni

Description

@goldbergyoni

Context: This is used to share my TOC of a new best practice so I can solicit feedback and ideas before start writing. From my experience, this makes the writing experience much easier and shorter. And fun.

Title: Shutdown gracefully

TL&DR: {Still writing}
Otherwise: Thousands of ongoing request will not get a response for no reason
Simple explanation: Frequently, Docker orchestrators stop and relocate containers as part of their routine tasks; Why? - scale-up, down, refresh, error; why is this important - solely the app responsibility to close thoughtfully, reply to ongoing requests, stop handling new requests, resource release; Why is this challenging - Multiple things happens in parallel, SIGTERM and 30 seconds timers, load balancer at some point will stop serving requests, close webserver but not the existing requests?
Advanced tip: Don't start Node via bash command or pm as the SIGTERM won't pass along
Advanced tip: What about keep-alive connection, use /npm/stopable
Code example: How to gracefully shutdown using Express
Code example Anti-pattern: Just log & exit
Code example Anti-pattern: Bash & npm start command
Illustration: Great drawing of the shutdown process from https://blog.risingstack.com/graceful-shutdown-node-js-kubernetes/

image

Thoughts? improvement? Help me to make it better

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions