Overview
Report generation incidents typically involve:- Synchronous file I/O blocking the event loop
- CPU-intensive operations blocking concurrent requests
- Memory issues with large data processing
Incidents
INC-105: Event Loop Blocked by Synchronous File Read
INC-105: Event Loop Blocked by Synchronous File Read
Summary
Severity: P2 - HighService: node-service
Date: 2026-02-28
Environment: ProductionThe
/api/reports/sales endpoint blocked the entire Node.js event loop for 3-5 seconds on each request. During this time, all other requests were queued, causing timeouts across the service.Problem
Monitoring showed:- Event loop lag: 3200ms (threshold: 100ms)
- p99 latency spike across ALL endpoints during report generation
- Thread pool utilization: 100%
/api/health.Root Cause
The report generation usedfs.readFileSync() to load a large HTML email template on every request. This synchronous file I/O operation blocked the single-threaded Node.js event loop.Problematic code (src/routes/reports.js:11-52):- Node.js is single-threaded
fs.readFileSync()is synchronous - it blocks until the file is completely read- During this time, no other JavaScript can execute
- All incoming requests queue up waiting for the event loop to be free
Resolution
Solution 1: Use async file operationsReplacefs.readFileSync() with async fs.promises.readFile():Prevention
Never use synchronous file operations in production:❌ Avoid:fs.readFileSync()fs.writeFileSync()fs.readdirSync()fs.statSync()
fs.promises.readFile()fs.promises.writeFile()fs.promises.readdir()fs.promises.stat()