Bug Bytes III: How to block your Node.js application đ±
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.
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. đ