haskell-servant / haskell-servant/servant
Exception in 'threadWait' after a while
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
I'm getting `threadWait: invalid argument (Bad file descriptor)` after a while when an endpoint has been triggered.
### Example code
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Data.Aeson (ToJSON)
import Data.Text as T
import GHC.Generics (Generic)
import Network.Wai.Handler.Warp (run)
import Servant (Application, Proxy(..), Server, serve)
import Servant.API ((:>), Get, JSON)
type ModuleAPI = "modules" :> Get '[JSON] [Module]
data Module = Module { moduleName :: T.Text }
deriving (Eq, Show, Generic)
instance ToJSON Module
mkModule :: T.Text -> Module
mkModule name = Module { moduleName = name }
modules :: [Module]
modules = [ mkModule "module#1" ]
server :: Server ModuleAPI
server = return modules
moduleAPI :: Proxy ModuleAPI
moduleAPI = Proxy
app :: Application
app = serve moduleAPI server
main :: IO ()
main = run 8080 app
```
### Steps to reproduce
1. Compile with profiling options
2. Start the application with `+RTS -xc`
3. Make a request against `http://localhost:8080/modules`
4. Wait for the exception stack trace to be printed to the console
### StackTrace
```
*** Exception (reporting due to +RTS -xc): (base:GHC.Exception.Type.SomeException), stack trace:
Network.Wai.Handler.Warp.Run.serveConnection.\,
called from Network.Wai.Handler.Warp.Recv.receiveloop,
called from Network.Wai.Handler.Warp.Recv.receive.\,
called from Network.Wai.Handler.Warp.Recv.receive,
called from Network.Wai.Handler.Warp.Run.socketConnection,
called from Network.Wai.Handler.Warp.Run.runSettingsSocket.getConn,
called from Network.Wai.Handler.Warp.Run.runSettingsConnection.getConnMaker,
called from Network.Wai.Handler.Warp.Run.acceptConnection.acceptNewConnection,
called from Network.Wai.Handler.Warp.Run.wrappedRecv,
called from Network.Wai.Handler.Warp.Types.mkSource,
called from Network.Wai.Handler.Warp.Types.readSource,
called from Network.Wai.Handler.Warp.Request.headerLines,
called from Network.Wai.Handler.Warp.Request.recvRequest,
called from Network.Wai.Handler.Warp.Run.serveConnection.http1,
called from Network.Wai.Handler.Warp.Run.serveConnection,
called from Network.Wai.Handler.Warp.Run.fork.serve.\.\,
called from Network.Wai.Handler.Warp.Run.fork.serve.\,
called from Network.Wai.Handler.Warp.Run.fork.serve,
called from Network.Wai.Handler.Warp.Run.fork.\.\,
called from Network.Wai.Handler.Warp.Run.fork.withClosedRef,
called from Network.Wai.Handler.Warp.Run.fork.\,
called from Network.Wai.Handler.Warp.Settings.defaultSettings,
called from Network.Wai.Handler.Warp.Settings.settingsFork,
called from Network.Wai.Handler.Warp.Run.fork,
called from Network.Wai.Handler.Warp.Run.acceptConnection.acceptLoop,
called from Network.Wai.Handler.Warp.Run.acceptConnection,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withII0.\.\.\.\,
called from Network.Wai.Handler.Warp.FileInfoCache.withFileInfoCache,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withII0.\.\.\,
called from Network.Wai.Handler.Warp.FdCache.withFdCache,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withII0.\.\,
called from Network.Wai.Handler.Warp.Date.withDateCache,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withII0.\,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withTimeoutManager,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure.withII0,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMakerSecure,
called from Network.Wai.Handler.Warp.Run.runSettingsConnectionMaker,
called from Network.Wai.Handler.Warp.Run.runSettingsConnection,
called from Network.Wai.Handler.Warp.Run.runSettingsSocket,
called from Network.Wai.Handler.Warp.Run.runSettings.\,
called from Network.Wai.Handler.Warp.Run.runSettings,
called from Network.Wai.Handler.Warp.Run.run,
called from Main.main
```
When adding a logger of some kind one can verify that the exception is `threadWait: invalid argument (Bad file descriptor)`. Is there anything I can do about this?
Contributor guide
Assessment
This issue has not been assessed yet.