summaryrefslogtreecommitdiff
path: root/Utility/WebApp.hs
diff options
context:
space:
mode:
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