1

I am making an handmade HTTP Proxy with NodeJS, but when there are many requests per seconds net.js is entering in an infinite loop while reading end of null connection. (it happens to random way around 40 req/s).

I separated the code that caused the bug creating a simple HTTP Proxy throwing the problem :

The code : https://gist.github.com/Ifnot/5336823

I put net.js to debug mode using command "NODE_DEBUG=net node main.js" and even when all connections seems to be closed the program output this indefinitely :

The debug : https://gist.github.com/Ifnot/5274181

NOTE : When the loop begin i can see this error :

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:653:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:527:26)

Am I doing something wrong ? Anyone know what happens ? Why this problem appear ?

(I am using node v0.10.4, problem was seen in previous version v0.9.x)

Ifnot
  • 4,914
  • 4
  • 33
  • 47
  • FWIW, [this line](https://gist.github.com/AnaelFavre/5336823#file-gistfile1-js-L31) contains a typo ('mathod' instead of 'method'). W.r.t. the warning you're getting, see http://stackoverflow.com/a/9768586/893780 – robertklep Apr 09 '13 at 10:53
  • Thanks for the fix, however i tried to put `process.setMaxListeners(0);` and `.setMaxListeners(0);` to the `httpServer` and the `http.ClientRequest` returned object by `http.get` and it changes nothing -> Look at the updated gist, am i doing it wrong ? – Ifnot Apr 09 '13 at 11:27
  • I'm not entirely sure what would happen when the client calling your code doesn't wait long enough for `http.get()` to return with a response, but other than that, I wouldn't know :( – robertklep Apr 09 '13 at 11:37
  • Tried a call of `httpRequest.abort();` when `request` `end` event, but nothing changed ... :( (see the updated gist) – Ifnot Apr 09 '13 at 11:45
  • Try setting `agent: false` in the options passed to `http.get()`, that will turn off HTTP keep-alives and will close the sockets when the request has finished (otherwise they are kept open for a certain amount of time). – robertklep Apr 09 '13 at 18:52
  • Nothing changed ... (gist updated). – Ifnot Apr 10 '13 at 07:53
  • I am running into the exact same error. And yes, I do see a loop as well. The RAM/CPU just increase after one error and after some time, the app crashes. – Dennis J Apr 13 '13 at 19:32
  • Please upvote the question if you are interested by an answer. Maybe it will bring more attention :) I hope ... – Ifnot Apr 14 '13 at 12:52
  • What OS are you running? – Dennis J Apr 20 '13 at 14:32
  • Debian 6 stable up to date. – Ifnot Apr 21 '13 at 11:48

1 Answers1

0

It is a bug from nodejs core. We are talking about here :

https://github.com/joyent/node/issues/5108

Bug comes after version 0.8.23, so the solution is to download and compile the node version 0.8.23 :

http://blog.nodejs.org/2013/04/08/node-v0-8-23-legacy/

Ifnot
  • 4,914
  • 4
  • 33
  • 47