shadowsocks-nodejs icon indicating copy to clipboard operation
shadowsocks-nodejs copied to clipboard

memory leak on Node v0.10

Open clowwindy opened this issue 12 years ago • 19 comments

clowwindy avatar Mar 30 '13 10:03 clowwindy

The newest version 0.10.2 works fine with me. 0.6.0 is not. with 0.6.0, CPU usage shoots to 100% and the thread exits unexpectedly quite often.

dallascao avatar Mar 31 '13 08:03 dallascao

Might this be the reason for the mem leak?

In versions of node prior to v0.10, the incoming message data would be simply discarded. However, in Node v0.10 and beyond, the socket will remain paused forever.

More info is at http://nodejs.org/api/stream.html#stream_compatibility

zhuzhuor avatar Apr 18 '13 02:04 zhuzhuor

@zhuzhuor No, it isn't.

clowwindy avatar Apr 18 '13 02:04 clowwindy

node v0.10.4 shadowsocks 0.10 dev Received an warning message when running. But it continues to work fine.

(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 Socket.destroySoon (net.js:413:10)
    at Socket.onSocketEnd (net.js:261:10)
    at Socket.EventEmitter.emit (events.js:92:17)
    at TCP.onread (net.js:535:10)

dallascao avatar Apr 18 '13 08:04 dallascao

Used as proxy for xunlei for several hours and memory footprint starts to go up.

$ ps aux|grep node
1000     29425  0.0 28.5 353452 292848 ?       Sl   Jun03   5:20 node server.js

$ node -v
v0.10.2

I'll check tomorrow after timeout 600s went out.

clowwindy avatar Jun 17 '13 17:06 clowwindy

Forcing gc() every few seconds seems help. c4ca46610d5cfa335aea2789508ce620bbede539

clowwindy avatar Jul 05 '13 15:07 clowwindy

Other possible causes:

  • pause() is not working in 0.10
  • write() buffer is too large?

It seems that inbound traffic is always a bit higher than outbound traffic.

if_venet0-day

clowwindy avatar Jul 29 '13 18:07 clowwindy

if_venet0-pinpoint 1375086309 1375194309

clowwindy avatar Jul 30 '13 14:07 clowwindy

Found a problem with crypto module https://github.com/joyent/node/issues/5949

clowwindy avatar Jul 30 '13 16:07 clowwindy

Is it resolved now? can I update node to v0.10?

regou avatar May 11 '14 03:05 regou

迅雷不是Thunder吗。。。

JiaJiaJiang avatar Jan 26 '15 15:01 JiaJiaJiang

Is this fixed on upgrade to 0.12 or iojs? From this "We have the new TLSWrap mechanism under the hood, this eliminates quite a few of the hops back and forth between JavaScript and our C++ implementations." so this would make the nodejs port at least faster I'd guess.

IMHO this is not a leak, at least what you've linked on https://github.com/joyent/node/issues/5949. Despite this comment from one of top node hackers, from my own experience such greedy memory consumption is common also to Java. I guess node will do better GC job when system is really under memory pressure but otherwise, it will eat as much as it can, just like what Java do for decreasing overhead of OS malloc.

ebraminio avatar Feb 08 '15 21:02 ebraminio

@ebraminio I have already abandoned this project. No matter this is a leak or not, I can not solve it. I have been debugging node and V8 source for several weeks without any progress.

Now I'm happy with Shadowsocks Python project. I can handle 10K connections with < 100MB RSS without having to think about GC.

clowwindy avatar Feb 09 '15 04:02 clowwindy

I'm working on a new version of shdowsocks-gui now. But I haven't touch shadowsocks-nodejs yet. If there's anybody who want to fork this project and keep working on it, I'd like integrate it into my shadowsocks-gui fork.

yaleh avatar Feb 09 '15 07:02 yaleh

nodejs 9.x ?

zuohuadong avatar Dec 04 '17 15:12 zuohuadong

This project has abandoned.

chenshaoju avatar Dec 05 '17 03:12 chenshaoju

nodejs now is on version 16. anyone tested it these days?

ehsan2003 avatar Jun 04 '21 14:06 ehsan2003

To complete the story, this is likely a backpressure related issue in earlier version of Streams, readable.pipe and stream.pipeline has been provided since v9 and v10 to free user from manual labor, and it's quite reliable nowadays.

imcotton avatar Nov 27 '22 18:11 imcotton

            node_args: ["--max_old_space_size=64", "--max_semi_space_size=2"],
            env: {
                "LD_PRELOAD": "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
            },

Using this parameter solves the memory problem.

FishOrBear avatar Nov 23 '23 03:11 FishOrBear