Bird
0
0

You want to create a cluster that automatically restarts a worker if it crashes. Which approach correctly implements this behavior?

hard📝 Application Q15 of 15
Node.js - Cluster Module
You want to create a cluster that automatically restarts a worker if it crashes. Which approach correctly implements this behavior?
AListen to the 'exit' event on cluster and fork a new worker inside the handler
BUse setInterval to fork new workers every second
CCall cluster.fork() only once at startup and never again
DUse cluster.disconnect() inside the worker to restart itself
Step-by-Step Solution
Solution:
  1. Step 1: Understand worker crash handling

    The primary process can listen to the 'exit' event when a worker dies.
  2. Step 2: Restart worker on exit

    Inside the 'exit' event handler, calling cluster.fork() creates a new worker to replace the crashed one.
  3. Final Answer:

    Listen to the 'exit' event on cluster and fork a new worker inside the handler -> Option A
  4. Quick Check:

    Restart crashed workers by handling 'exit' event [OK]
Quick Trick: Use 'exit' event to restart workers automatically [OK]
Common Mistakes:
  • Forking workers repeatedly with setInterval causes overload
  • Not restarting workers after crash leads to downtime
  • Using cluster.disconnect() inside worker does not restart it

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes