<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anton K.</title>
    <description>The latest articles on DEV Community by Anton K. (@jsak).</description>
    <link>https://dev.to/jsak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F798380%2Ff70663ec-3f64-4c59-9885-21890f0f20ee.png</url>
      <title>DEV Community: Anton K.</title>
      <link>https://dev.to/jsak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jsak"/>
    <language>en</language>
    <item>
      <title>How to Detect Event Loop Freezes in Node.js</title>
      <dc:creator>Anton K.</dc:creator>
      <pubDate>Thu, 23 Jul 2026 12:50:14 +0000</pubDate>
      <link>https://dev.to/jsak/how-to-detect-event-loop-freezes-in-nodejs-347o</link>
      <guid>https://dev.to/jsak/how-to-detect-event-loop-freezes-in-nodejs-347o</guid>
      <description>&lt;p&gt;You've probably seen this: Kubernetes probes are green, /health returns 200, CPU isn't on fire - and users are timing out.&lt;/p&gt;

&lt;p&gt;Process is up. Just not doing anything useful.&lt;/p&gt;

&lt;p&gt;Classic event loop freeze. Something sync and expensive (or a dumb busy loop) grabs the thread, and suddenly timers, HTTP, DB callbacks - all of it waits. Including your health endpoint, because that also needs the loop.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;monitorEventLoopDelay()&lt;/code&gt; is fine for dashboards. It won't yell at you while the process is stuck, and it definitely won't write a log line from outside the frozen loop.&lt;/p&gt;

&lt;p&gt;That's the part that annoyed me enough to build this.&lt;/p&gt;

&lt;p&gt;I made &lt;a href="https://www.npmjs.com/package/@js-ak/watchdog" rel="noopener noreferrer"&gt;@js-ak/watchdog&lt;/a&gt; - tiny N-API addon. The monitor runs in C++ on its own thread and writes JSON lines to stderr/file even while the JS event loop is stuck. Your &lt;code&gt;freeze&lt;/code&gt; / &lt;code&gt;recovered&lt;/code&gt; handlers only run after the loop unblocks. Optional RSS/CPU, optional stack sample.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @js-ak/watchdog

const watchdog = require("@js-ak/watchdog");

watchdog.on("freeze", (e) =&amp;gt; console.log(e.event, e.duration_ms));
watchdog.on("recovered", (e) =&amp;gt; console.log("back after", e.duration_ms, "ms"));

watchdog.start({
  freezeThresholdMs: 1000,
  logTarget: "stderr", // or "file" | "both"
  source: "payments-api",
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Real freezes usually aren't &lt;code&gt;while (true)&lt;/code&gt;. More like giant JSON.parse, a cursed regex, sync crypto/compress, or some dependency doing sync I/O on a hot path. Stuff you only notice after people complain.&lt;/p&gt;

&lt;p&gt;Prebuilds for the usual platforms (Node 22+). MIT.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/JS-AK/watchdog" rel="noopener noreferrer"&gt;https://github.com/JS-AK/watchdog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Curious how other people catch loop stalls in prod - and what you'd actually want in the freeze payload. Roast the API if it's wrong.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>monitoring</category>
      <category>node</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
