{"id":5803,"date":"2016-10-03T10:58:15","date_gmt":"2016-10-03T15:58:15","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=5803"},"modified":"2016-10-03T10:58:15","modified_gmt":"2016-10-03T15:58:15","slug":"impact-of-socket-so_reuseaddr","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2016\/10\/03\/impact-of-socket-so_reuseaddr\/","title":{"rendered":"Impact of socket.SO_REUSEADDR"},"content":{"rendered":"<p>This is often used to get around an &#8220;address already in use&#8221; error.  If you know the previous server program has been shutdown, you can set this socket option prior to the initial server bind, and then restart your program.  However, there is risk.  A TIME_WAIT status on a socket is designed to provide safety when a &#8220;late&#8221; packet arrives on a host:port combo from a previous incarnation of a program using that combo.  The OS will normally retain a file handle to the host:port combo for a time twice that of the MSL (Max Segment Lifetime) to ensure this is not the case.<\/p>\n<p>Again, if you know your program and are sure there will be no issues with &#8220;late&#8221; packets such as those described arriving to a subsequent incarnation, you can set this on the server socket and get your program started more quickly.  If you can wait for the number of seconds defined as a timeout for the TIME_WAIT status, you can simply wait, restart, then get a successful bind without setting the REUSEADDR parameter.  This value in seconds can be obtained with what is below&#8230;<\/p>\n<pre>\r\n$cat \/proc\/sys\/net\/ipv4\/tcp_fin_timeout\r\n60\r\n$\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is often used to get around an &#8220;address already in use&#8221; error. If you know the previous server program has been shutdown, you can set this socket option prior to the initial server bind, and then restart your program.&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2016\/10\/03\/impact-of-socket-so_reuseaddr\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[28,56],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5803"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=5803"}],"version-history":[{"count":9,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5803\/revisions"}],"predecessor-version":[{"id":5813,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5803\/revisions\/5813"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5803"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}