Hi Haskell Cafe,
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
- connection refusals or
- deadlock.
Before I sink time into reading the source of the packages in question, does anybody see what's wrong with the code below?
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".
Thank you for taking a look.
--Patrick
module Lib ( someFunc ) whereimport Control.Monad.IO.Class (liftIO)import qualified Control.Concurrent as Concurrentimport qualified Control.Concurrent.Async as Asyncimport qualified Control.Exception as Exceptionimport qualified Data.Maybe as Maybeimport qualified Network.Browser as Browserimport qualified Network.HTTP as HTTPimport qualified Network.HTTP.Server as Serverimport qualified Network.HTTP.Server.Logger as ServerLimport qualified Network.HTTP.Server.Response as ServerRimport qualified Network.URI as URIsomeFunc :: IO (Either Exception.SomeException (URI.URI, HTTP.Response String))someFunc = do Async.withAsync (Server.serverWith config handler) $ \_ -> do Concurrent.threadDelay . round $ 2e6 Exception.try . Browser.browse . Browser.request . Browser.defaultGETRequest $ uri where uri = Maybe.fromJust . URI.parseURI $ "http://localhost:8080/" config = Server.Config ServerL.stdLogger "localhost" 8080 handler _ url req = return (ServerR.respond ServerR.OK :: Server.Response String)