FiFtHeLeMeNt
FiFtHeLeMeNt

Reputation: 31

socket.end() or socket.destroy() to ensure file descriptor is released?

I am writing a proxy app in nodejs which handles thousands of concurrent connections inwards and outwards

I want to make sure all idle and unneeded connections get closed properly and their file descriptors get released. If it leaks file descriptors, I would run out of them very fast.

My question is that :

what is the best solution to make sure a connection gets closed ? socket.end() or socket.destroy() ?

Currently I am using socket.end() but in doc it says it half closes the connection, is there a situation that socket.end() doesn't result in closing a connection ? what I am interested in is releasing the file descriptors ASAP.

So what do you suggest ?

Upvotes: 3

Views: 2889

Answers (1)

Anshul Verma
Anshul Verma

Reputation: 1091

socket.end() is a much better way to gracefully terminate your connections. socket.destroy terminates all of your connections immediately. Also, due to a bug, in most of the cases one had to add socket.end after destroy to make it work.
So end() is the way to go!

Upvotes: 2

Related Questions