<div dir="ltr">Hi Haskell Cafe,<br><br>When I start a web server (http-server:Network.HTTP.Server.serverWith) on a separate thread (async:Control.Concurrent.Async.withAsync) and then try to retrieve a response from the server (HTTP:Network.Browser.*) on a threaded runtime, I see either<br><ul><li>connection refusals or<br></li><li>deadlock.<br></li></ul>Before I sink time into reading the source of the packages in question, does anybody see what's wrong with the code below?<br><br>Increasing the timeout to wait for the server to initialize doesn't solve the problem. Using a bound thread doesn't solve the problem. I'm compiling with options "-threaded -rtsopts -with-rtsopts=-N".<br><br>Thank you for taking a look.<br>--Patrick<div><br></div><div><a href="https://github.com/plredmond/http-server-test-hs/blob/master/src/Lib.hs">This test project is on github.</a></div><div><br><font face="monospace, monospace">module Lib</font><br><font face="monospace, monospace">    ( someFunc</font><br><font face="monospace, monospace">    ) where</font><br><br><font face="monospace, monospace">import Control.Monad.IO.Class (liftIO)</font><br><font face="monospace, monospace">import qualified Control.Concurrent as Concurrent</font><br><font face="monospace, monospace">import qualified Control.Concurrent.Async as Async</font><br><font face="monospace, monospace">import qualified Control.Exception as Exception</font><br><font face="monospace, monospace">import qualified Data.Maybe as Maybe</font><br><font face="monospace, monospace">import qualified Network.Browser as Browser</font><br><font face="monospace, monospace">import qualified Network.HTTP as HTTP</font><br><font face="monospace, monospace">import qualified Network.HTTP.Server as Server</font><br><font face="monospace, monospace">import qualified Network.HTTP.Server.Logger as ServerL</font><br><font face="monospace, monospace">import qualified Network.HTTP.Server.Response as ServerR</font><br><font face="monospace, monospace">import qualified Network.URI as URI</font><br><br><font face="monospace, monospace">someFunc :: IO (Either Exception.SomeException (URI.URI, HTTP.Response String))</font><br><font face="monospace, monospace">someFunc = do</font><br><font face="monospace, monospace">    Async.withAsync (Server.serverWith config handler) $ \_ -> do</font><br><font face="monospace, monospace">        Concurrent.threadDelay . round $ 2e6</font><br><font face="monospace, monospace">        Exception.try . Browser.browse . Browser.request . Browser.defaultGETRequest $ uri</font><br><font face="monospace, monospace">    where</font><br><font face="monospace, monospace">        uri = Maybe.fromJust . URI.parseURI $ "<a href="http://localhost:8080/">http://localhost:8080/</a>"</font><br><font face="monospace, monospace">        config = Server.Config ServerL.stdLogger "localhost" 8080</font><br><font face="monospace, monospace">        handler _ url req = return (ServerR.respond ServerR.OK :: Server.Response String)</font></div></div>