Bird
0
0

You want to implement a graceful shutdown that waits for all active HTTP requests to finish before exiting. Which approach is best?

hard📝 Application Q8 of 15
Node.js - Error Handling Patterns
You want to implement a graceful shutdown that waits for all active HTTP requests to finish before exiting. Which approach is best?
AThrow an error to trigger uncaughtException handler
BCall process.exit() immediately on shutdown signal
CCall server.close() and wait for its callback before calling process.exit()
DIgnore shutdown signals and let the OS kill the process
Step-by-Step Solution
Solution:
  1. Step 1: Understand server.close behavior

    server.close stops new connections and waits for existing ones to finish.
  2. Step 2: Use callback to exit after all requests finish

    Waiting for server.close callback ensures all active requests complete before exit.
  3. Final Answer:

    Call server.close() and wait for its callback before calling process.exit() -> Option C
  4. Quick Check:

    Wait for server.close callback before exit [OK]
Quick Trick: Wait for server.close callback to finish requests before exit [OK]
Common Mistakes:
  • Exiting immediately
  • Ignoring shutdown signals
  • Using errors to trigger shutdown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes