lifetime of net sockets

41 views
Skip to first unread message

ad...@zemplex.com

unread,
Aug 21, 2014, 1:58:27 AM8/21/14
to nod...@googlegroups.com
function someFunc(){
    var server = net.createServer()
    server.on('connection', function(socket){
        socket.on('data', function(data){
        })
        socket.on('error', function(err){
        })
        socket.on('close', function(){
       })
    })
}

I have the structure above for accepting connections. someFunc() is run once and I can see incoming connections appearing with each 'connection' event.
Why do the sockets keep working after the 'connection' event handler returns?
Given that they do keep working indefinitely, what must I do to ensure they get garbage collected once closed?

Sam Roberts

unread,
Aug 22, 2014, 4:35:43 AM8/22/14
to nod...@googlegroups.com
On Wed, Aug 20, 2014 at 10:58 PM, <ad...@zemplex.com> wrote:
> Why do the sockets keep working after the 'connection' event handler
> returns?

Because the server keeps references to all its connections (until they
close). And the (internal) epoll loop keeps a reference to the server,
because it is attached and listening.

> Given that they do keep working indefinitely,

They only keep working until they close.

> what must I do to ensure they
> get garbage collected once closed?

Nothing.
Reply all
Reply to author
Forward
0 new messages