socksv5 icon indicating copy to clipboard operation
socksv5 copied to clipboard

All successful client sockets are not closed

Open louislam opened this issue 4 years ago • 2 comments

As topic.

If you use this server as a web proxy, because websites nowadays make a lot of requests, it also creates a lot of sockets on socksv5 server. As all successful sockets are not closed, it will eats up all system resources and emits EMFILE error shortly. As a result, the server is no longer working anymore.

After some investigations, in server.js, I found out that after the dstSock (the socket between proxy server and destination server) is closed, it do not close the client socket together.

To fix this, just need to add close event and destroy the client socket.

server.js

function proxySocket(socket, req) {

    ....

    dstSock
            .on('error', onError)
            //////////// Missing Part ///////////
            .on('close', () => {
              socket.end()
              socket.destroy()
            })
           //////////// Missing Part End ////////////////////
           .on('connect', function() {
             connected = true;
             if (socket.writable) {

    ....

However, it seems that this project is abandoned. My recommendation is you should not use this library.

louislam avatar Apr 15 '21 09:04 louislam

You're a life saver.

israelsgalaxy avatar Jan 12 '23 21:01 israelsgalaxy

In theory piped sockets are closed automatically when the source stream emits 'end': https://nodejs.org/api/stream.html#readablepipedestination-options

Anyway, if node doesn't do what it says it does, better do it manually.

kzar79 avatar Aug 19 '23 11:08 kzar79