Bird
0
0

Identify the error in the following code snippet that attempts to restart a worker on crash:

medium📝 Debug Q6 of 15
Node.js - Cluster Module
Identify the error in the following code snippet that attempts to restart a worker on crash:
cluster.on('exit', (worker) => {
  cluster.fork();
});
AMissing parameters to check why worker exited
BCalling cluster.fork() inside exit event causes infinite forks
CNo error; code correctly restarts worker
DShould use worker.restart() instead of cluster.fork()
Step-by-Step Solution
Solution:
  1. Step 1: Check exit event parameters

    The exit event provides (worker, code, signal) to understand exit reason.
  2. Step 2: Importance of parameters

    Without code or signal, you cannot decide if restart is needed or handle errors properly.
  3. Final Answer:

    Missing parameters to check why worker exited -> Option A
  4. Quick Check:

    Exit event needs parameters to handle restarts properly [OK]
Quick Trick: Use all exit event parameters to handle restarts safely [OK]
Common Mistakes:
  • Ignoring exit code and signal
  • Assuming cluster.fork causes infinite forks
  • Using non-existent worker.restart() method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes