{"id":32,"date":"2016-04-01T14:47:54","date_gmt":"2016-04-01T22:47:54","guid":{"rendered":"http:\/\/iaastalk.com\/?p=32"},"modified":"2016-04-01T14:47:54","modified_gmt":"2016-04-01T22:47:54","slug":"quickly-detect-tcp-disconnection","status":"publish","type":"post","link":"http:\/\/iaastalk.com\/?p=32","title":{"rendered":"Quickly detect TCP disconnection"},"content":{"rendered":"<p>Application may be blocked on reading TCP scocket I\/O\u00a0 when connection was dropped.\u00a0 It could take up to 2 hours for application to detect this disconnection without a separate thread monitoring network heatbeat(Application level heatbeat ) and TCP native keepalive enabled and tune.<\/p>\n<p>TCP keepalive is an optional feature and has to be explicitly enabled when creating a new sockets.\u00a0 Tune the following using sysctl and persist the change in \/etc\/sysctl.conf as well.<\/p>\n<p>net.ipv4.tcp_keepalive_time=10<br \/>\nnet.ipv4.tcp_keepalive_probes=2<br \/>\nnet.ipv4.tcp_keepalive_intvl=3<\/p>\n<p>The above means heatbeats will be sent every 10s. If no response received for the corresponding heartbeat, another heartbeat will be sent out every 3 sends.\u00a0 If 2 response (probes) missed, connection will be regarded as dropped and blocking I\/O will be signaled.\u00a0 Application thus get a chance to return from blocking I\/O and receive an error or exception for re-establish a new connection.<\/p>\n<p>Futher tuning can be done on tcp_user_timeout, fin-wait, fin-wait2, close-wait, for more details please read the following pages.<\/p>\n<p><a href=\"https:\/\/bugs.launchpad.net\/nova\/+bug\/856764\">Patching RMQ issue<\/a><\/p>\n<p><a href=\"http:\/\/openstack-qe-guy.blogspot.com\/2015\/11\/rabbitmq-best-practices.html\">&#8220;RabbitMQ Best Practices&#8221;<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/5907527\/application-control-of-tcp-retransmission-on-linux\">TCP_USER_TIMEOUT<\/a><\/p>\n<p><a href=\"http:\/\/tldp.org\/HOWTO\/TCP-Keepalive-HOWTO\/overview.html\">TCP keepalive overview<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Application may be blocked on reading TCP scocket I\/O\u00a0 when connection was dropped.\u00a0 It could take up to 2 hours for application to detect this disconnection without a separate thread monitoring network heatbeat(Application level heatbeat ) and TCP native keepalive enabled and tune. TCP keepalive is an optional feature and has to be explicitly enabled [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/32"}],"collection":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=32"}],"version-history":[{"count":1,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":33,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions\/33"}],"wp:attachment":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}