Event loop blocking: synchronous code chiếm CPU lâu khiến event loop không xử lý được I/O callbacks, timers, requests khác.
Ví dụ thực tế:
JSON.parse(fs.readFileSync('huge.json'))— 200MB JSON parse tốn ~2s block hoàn toàn;- regex backtracking —
/^(a+)+$/.test('aaaaaaaaab')chạy exponential time với input độc hại (ReDoS); - crypto sync —
crypto.pbkdf2Sync()trong request handler; - nested loops O(n²) trên large arrays
Đo blocking: node --prof app.js tạo V8 profile; clinic doctor -- node app.js từ clinic.js package hiển thị event loop lag rõ ràng; perf_hooks API đo eventLoopUtilization().
Fix: chia nhỏ task với setImmediate() để yield event loop giữa chunks; offload sang Worker Threads cho CPU-intensive; dùng streaming thay vì load toàn bộ vào memory; safe-regex package detect ReDoS vulnerable patterns.
Threshold: bất kỳ synchronous operation > 10ms trong request handler là vấn đề cần xem xét.