Tuesday 12 December 2017

Weird setTimeout() bug for multiple processes, Ctrl+C magically restores code execution.

I have a bunch of different nodejs apps (or processes) that I run on the same machine. Some of those use setTimeout() to delay code execution (I'm retrieving stuff from an online server). When I run a single nodejs app (with "node myapp.js") everything runs fine. If I run 2 or more (with "node myapp.js" and "node anotherapp.js") somehow they bot get stuck.The callback used on setTimeout() is not called anymore (I think because I've logged it and that's the point in code where it stops). The really weird thing is that I can unstuck it by going to the powershell window where I've initiall started my nodejs app and press Ctrl + C - which should kill the app completely but it doesn't - it magically continues the code execution. This doesn't happen all the time though and so it's hard to debug it. I'm thinking maybe node loses track of the timeout variables - I'm not using any by the way, that is I call setTimeout() directly and not asigning it to a var.Any thoughts or sugestions are welcome. Thanks!

Submitted December 12, 2017 at 08:34PM by odonian_dream

No comments:

Post a Comment