[Haskell-cafe] make a server & connect to it - strange behavior
plredmond at gmail.com
Mon Nov 30 07:45:18 UTC 2015
For any curious, I found a smaller example of the root cause and sorted it
out. The previously linked-to repo is no longer up.
The http-server library requires that the provided handler function appends
a "Connection: close" to the response, or it leaves the connection open.
On Thu, Nov 26, 2015 at 1:10 AM, Patrick Redmond <plredmond at gmail.com>
> 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.
> This test project is on github.
> module Lib
> ( someFunc
> ) where
> import Control.Monad.IO.Class (liftIO)
> import qualified Control.Concurrent as Concurrent
> import qualified Control.Concurrent.Async as Async
> import qualified Control.Exception as Exception
> import qualified Data.Maybe as Maybe
> import qualified Network.Browser as Browser
> import qualified Network.HTTP as HTTP
> import qualified Network.HTTP.Server as Server
> import qualified Network.HTTP.Server.Logger as ServerL
> import qualified Network.HTTP.Server.Response as ServerR
> import qualified Network.URI as URI
> someFunc :: IO (Either Exception.SomeException (URI.URI, HTTP.Response
> someFunc = do
> Async.withAsync (Server.serverWith config handler) $ \_ -> do
> Concurrent.threadDelay . round $ 2e6
> Exception.try . Browser.browse . Browser.request .
> Browser.defaultGETRequest $ uri
> 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)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe