node.js - infinite loop during JSONStream <p>I've got a node.js server that is freezing in production, and it appears to be caused by an infinite loop inside of JSONStream. Here's a stack trace captured from a core dump from a frozen server:</p> <pre><code>1: toString [buffer.js:~392] (this=0x1e28fb6d25c9 &lt;a Buffer&gt;#1#,encoding=0x266ee104121 &lt;undefined&gt;,start=0x266ee104121 &lt;undefined&gt;,end=0x266ee104121 &lt;undefined&gt;) 2: arguments adaptor frame: 0-&gt;3 3: write [/home/deploy/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js:136] (this=0x32cc8dd5a999 &lt;a Parser&gt;#2#,buffer=0x32cc8dd5aa49 &lt;a Buffer&gt;#3#) 4: /* anonymous */ [/home/deploy/node_modules/JSONStream/index.js:~17] (this=0x32cc8dd5ab11 &lt;a Stream&gt;#4#,chunk=0x32cc8dd5aa49 &lt;a Buffer&gt;#3#) 5: write [/home/deploy/node_modules/JSONStream/node_modules/through/index.js:~24] (this=0x32cc8dd5ab11 &lt;a Stream&gt;#4#,data=0x32cc8dd5aa49 &lt;a Buffer&gt;#3#) 6: write [_stream_readable.js:~582] (this=0x266ee106c91 &lt;JS Global Object&gt;#5#,dest=0x32cc8dd5ab11 &lt;a Stream&gt;#4#,i=0,list=0x266ee104101 &lt;null&gt;) 7: flow [_stream_readable.js:592] (this=0x266ee106c91 &lt;JS Global Object&gt;#5#,src=0x32cc8dd5ac69 &lt;an IncomingMessage&gt;#6#) 8: /* anonymous */ [_stream_readable.js:560] (this=0x266ee106c91 &lt;JS Global Object&gt;#5#) 9: _tickCallback [node.js:415] (this=0x29e7331bb2a1 &lt;a process&gt;#7#) </code></pre> <p>How can I find the source of this infinite loop?</p> <p>Unfortunately the servers are running in production and are processing many thousands of requests, so it's difficult to give any additional context. The basic function of the servers is to make outbound HTTP requests for other services.</p> <p>It's worth noting that I don't believe this is caused by a memory leak. The server's memory usage remains constant (and low) during these freeze events, while the CPU spikes to 99%</p> <p>Another piece of evidence towards the conclusion of an infinite loop is that the event loop itself seems to have stopped. When I put a console.log inside of a setInterval, the server will stop outputting as soon as it freezes.</p> <p>We have verified that the problem is not caused by expired/corrupted socket connections, by setting the number of max connections to Infinity (which disables their reuse in node.js)</p> <p>We're using JSONStream 0.7.1 (which includes a default jsonparse version of 0.0.5). We found <a href="https://github.com/creationix/jsonparse/pull/22" rel="nofollow">this issue</a> on the JSONStream repo, and tried forking JSONParse and only updating to the newest jsonparse version. It did NOT fix the issue.</p>