{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/4560","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/4560/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/4560/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/4560/events","html_url":"https://github.com/nodejs/node/issues/4560","id":125311151,"number":4560,"title":"socket stay in ESTABLISHED status","user":{"login":"gogorush","id":1578784,"avatar_url":"https://avatars.githubusercontent.com/u/1578784?v=3","gravatar_id":"","url":"https://api.github.com/users/gogorush","html_url":"https://github.com/gogorush","followers_url":"https://api.github.com/users/gogorush/followers","following_url":"https://api.github.com/users/gogorush/following{/other_user}","gists_url":"https://api.github.com/users/gogorush/gists{/gist_id}","starred_url":"https://api.github.com/users/gogorush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogorush/subscriptions","organizations_url":"https://api.github.com/users/gogorush/orgs","repos_url":"https://api.github.com/users/gogorush/repos","events_url":"https://api.github.com/users/gogorush/events{/privacy}","received_events_url":"https://api.github.com/users/gogorush/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/net","name":"net","color":"eb6420"},{"url":"https://api.github.com/repos/nodejs/node/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-01-07T02:52:14Z","updated_at":"2016-09-26T08:36:38Z","closed_at":"2016-09-26T08:36:38Z","body":"Hello, guys\r\n\r\nI found myself in trouble with closing socket properly in nodejs.\r\nI tried to close socket connections from server side(nodejs side) with socket.end() (with socket.destroy() function follows, just to make sure about everything I can do with Javascript). But I found out lots of sockets are not closed (using ss & netstat) and stay in ESTABLISHED status forever.\r\nThe problem is : I already called socket.end() and listen to the 'close' event (for logging and sure the socket is 'closed' by javascript code).Lots of the sockets supposed to be closed while still open when I check socket connections with netstat. The only difference I could think of is the networks are generally bad in reality so that if send FIN to client, there would be no response and sockets hang there forever. What I don't understand is after I called end() and destroy() in nodejs, the socket is expected be jumped into FIN_WAIT mode.\r\nThe solution I used is setKeepAlive(true). And then the ESTABLISHED sockets could be closed do to the check packages from the system level (By setting net.ipv4.tcp_keepalive_time). \r\nI found thread https://github.com/nodejs/node-v0.x-archive/issues/3613 is about sockets stay in FIN_WAIT2 status. Not sure if it is connected with my problem.\r\n\r\nPlantform: Ubuntu 14.04\r\nNode : 4.2.x\r\nCPU: 48 cores Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz\r\nMemory: 128GB\r\nSome system settings:\r\n```\r\nnet.ipv4.tcp_sack = 1\r\nnet.ipv4.tcp_window_scaling = 1\r\nnet.ipv4.tcp_rmem = 4096        87380   4194304\r\nnet.ipv4.tcp_wmem = 4096        16384   4194304\r\nnet.core.wmem_default = 8388608\r\nnet.core.rmem_default = 8388608\r\nnet.core.rmem_max = 16777216\r\nnet.core.wmem_max = 16777216\r\nnet.core.netdev_max_backlog = 262144\r\nnet.core.somaxconn = 2621440\r\nnet.ipv4.tcp_max_orphans = 3276800\r\nnet.ipv4.tcp_max_syn_backlog = 2621440\r\nnet.ipv4.tcp_timestamps = 0\r\nnet.ipv4.tcp_synack_retries = 1\r\nnet.ipv4.tcp_syn_retries = 1\r\nnet.ipv4.tcp_tw_recycle = 0\r\nnet.ipv4.tcp_tw_reuse = 1\r\nnet.ipv4.tcp_mem = 94500000 915000000 927000000\r\nnet.ipv4.tcp_fin_timeout = 1\r\nnet.ipv4.tcp_keepalive_time = 30\r\nnet.ipv4.ip_local_port_range = 1024    65000\r\nvm.overcommit_memory=1\r\nnet.ipv4.tcp_max_tw_buckets = 6000\r\nnet.netfilter.nf_conntrack_max=13107200\r\nvm.swappiness = 20\r\nfs.file-max = 8000000\r\nfs.nr_open = 8000000\r\n```"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/249511056","html_url":"https://github.com/nodejs/node/issues/4560#issuecomment-249511056","issue_url":"https://api.github.com/repos/nodejs/node/issues/4560","id":249511056,"user":{"login":"gogorush","id":1578784,"avatar_url":"https://avatars.githubusercontent.com/u/1578784?v=3","gravatar_id":"","url":"https://api.github.com/users/gogorush","html_url":"https://github.com/gogorush","followers_url":"https://api.github.com/users/gogorush/followers","following_url":"https://api.github.com/users/gogorush/following{/other_user}","gists_url":"https://api.github.com/users/gogorush/gists{/gist_id}","starred_url":"https://api.github.com/users/gogorush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogorush/subscriptions","organizations_url":"https://api.github.com/users/gogorush/orgs","repos_url":"https://api.github.com/users/gogorush/repos","events_url":"https://api.github.com/users/gogorush/events{/privacy}","received_events_url":"https://api.github.com/users/gogorush/received_events","type":"User","site_admin":false},"created_at":"2016-09-26T08:36:38Z","updated_at":"2016-09-26T08:36:38Z","body":"@eladnava Thx, and this was my solution as well. Seems it is working very fine til now considering the amount of connections to my server(millions). Sorry I did not write them down here earlier, but end(), destroy() with timeout function worked. Thx again for your work and I am gonna close this issue now."}}
{"actor":{"display_login":"gogorush"}}