pascalopitz/nodestalker

looks like there is a problem getting a connection after about 20000-30000 requests are processed.

kiakj opened this issue · 6 comments

kiakj commented

I'm running a batch process and it hits this error consistently after 20000-30000 jobs.

version 0.1.21

events.js:141
throw er; // Unhandled 'error' event
^

Error: connect EADDRNOTAVAIL localhost:11300 - Local (localhost:0)
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at connect (net.js:843:14)
at net.js:938:9
at nextTickCallbackWith0Args (node.js:452:9)
at process._tickCallback (node.js:381:13)

Looks like stack overflow to me. If you use their approach from README, it will cause it, for sure.

@kanazir What alternative approach would you suggest?

Well, I am not the expert in node (I used it in only once in small IoT project) but you should not call the function recursively because it will cause stack overflow, eventually (javascript has no tail recursion). The better approach is to emit an event (and call callback function) every time the data is received.

For example, serialport does it that way.

I hope this helps...

If that is your concern node version 6.2 supports tail call optimization:
http://node.green/#proper-tail-calls--tail-call-optimisation-

Using setTimeout(resJob, 0) in the example provided, even if recursive, it would clear the call stack. I have tested it and it is a simpler alternative to using events.