Bug Bytes III: How to block your Node.js application đŸ˜±

Rajat Kanti Bhattacharjee
csmadeeasy
Published in
2 min readMay 23, 2020

This one will be a quickie. I am not as quick as this research paper which is nonsensically the world’s shortest paper . But this one will be quick. So I am doing lot of node.js these days. Like a lot. Most of it is back-end stuff. And apparently being too finicky about performance of my application I did a huge blunder.

Look and tell what’s wrong. Not for seasoned developers. Only rookies like me.

Question is will this halt. The straight answer is NO. But you may ask didn’t turned that into Promise i.e made it async. Didn’t I call reject method asynchronously at some threshold point in future. (I can hear devs already having a sigh!! over why would I use setInterval for a one of callback task, I know I just realized it later after writing it in a jiffy).

Well apparently you did everything right programmatically speaking , but this ain’t Java, and apparently everything is running in one single thread, that means the event loop is single threaded. That means there is a global while loop (for simplification purpose) that checks for various events like timeouts, intervals , os fileread/network calls and your javascript function code. Problem is when u created that while loop , with really large input you essentially stopped that global while loop. So what happened is that the event loop could never reach the next tick or next iteration of loop and hence could not check for the timeout/interval completion . Since it could not do that it never could push the callback function in stack. So your while loop or one of those regex expression working in your back-end apparently got a 16Gb payload , because they read my article or checked the official node.js youtube channel or are following synk.io. 😏

--

--

Rajat Kanti Bhattacharjee
csmadeeasy
Editor for

Your everyday programmer. Talking about everyday engineering. Love natural science, physics buff and definitely not good at no-scope 360.