Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

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 ?

like image 832
FiFtHeLeMeNt Avatar asked Oct 19 '25 11:10

FiFtHeLeMeNt


1 Answers

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!

like image 157
Anshul Verma Avatar answered Oct 22 '25 00:10

Anshul Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!