Advanced·Scenario·2 min read

The event loop is blocked. What do I do?

Practice this question

Short explanation:

An event-loop block happens when synchronous JavaScript occupies the thread long enough to delay other callbacks. Requests can appear to hang even when their own logic is simple because they share that scheduling thread. Measuring loop delay and CPU profiles connects the symptom to a specific workload.

Key points:

  • Check event-loop delay and capture a CPU profile.

  • Look for synchronous I/O, large JSON work, expensive regex or long loops.

  • Reduce the work or move CPU-heavy tasks to worker threads/jobs.

  • Large JSON serialization can block too; do not check only explicit loops or synchronous file APIs.

  • Apply input limits or chunking where appropriate, and use a worker pool for substantial CPU work.

Interview point:

  • Adding async to the function does not move the computation to another thread.
Adapted from 08_PERFORMANCE_SECURITY.md · “5. The event loop is blocked. What do I do?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.