summaryrefslogtreecommitdiff
path: root/Utility/WebApp.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@oberon.underhill.private>2012-09-27 12:22:50 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-27 12:23:27 -0400
commit3491f9b9d0a7cdeb805982176ea136d46737d5ae (patch)
tree892a71eebb6e45744a2f880a89ecff0eaab3fc54 /Utility/WebApp.hs
parent8979ea512eae7e8f7cdd9aa5cba6d176232dfe66 (diff)
retry bind
This is a workaround for bind failing with EINVAL sometimes on OSX. I don't know why; EVINAL should mean the socket is already bound to an address, but this is with a new socket.
Diffstat (limited to 'Utility/WebApp.hs')
-rw-r--r--Utility/WebApp.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs
index 21a5761bc..3a55bd74a 100644
--- a/Utility/WebApp.hs
+++ b/Utility/WebApp.hs
@@ -80,7 +80,14 @@ localSocket = do
{ addrFlags = [AI_ADDRCONFIG]
, addrSocketType = Stream
}
- go addr = bracketOnError (open addr) close (use addr)
+ {- Repeated attempts because bind sometimes fails for an
+ - unknown reason on OSX. -}
+ go addr = go' 100 addr
+ go' :: Int -> AddrInfo -> IO Socket
+ go' 0 _ = error "unable to bind to local socket"
+ go' n addr = do
+ r <- tryIO $ bracketOnError (open addr) close (use addr)
+ either (const $ go' (pred n) addr) return r
open addr = socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
close = sClose
use addr sock = do