Skip to content

Detecting when connections are closed #394

@neongreen

Description

@neongreen

tl;dr My goal is to get some action to reliably execute whenever an http-client connection times out. I tried modifying connectionClose, but without luck.


Example here: https://github.com/neongreen/http-client-destroy.

  • Start listening on port :12777 (nc -l -k 12777).
  • Run my example and press Enter several times.
  • A POST request is made on each Enter with a timeout of 5 seconds.
  • When the connection is closed (connectionClose), "destroying" is printed.

I expected that every connection that is timing out would be followed by "destroying". In reality, it's very inconsistent. Sometimes I get "destroying" for a connection, especially if it's the first or second connection, but mostly I don't.

The meat of the example is as follows:

    manager <- newManager defaultManagerSettings
        { managerResponseTimeout = responseTimeoutMicro 5000000
        , managerRawConnection = do
              mkConn <- managerRawConnection defaultManagerSettings
              pure $ \ha s i -> onDestroy (putStrLn "destroying") <$> mkConn ha s i
        }
    runResourceT $ for_ [(1::Int) ..] $ \i -> do
        _ <- liftIO getLine
        initialRequest <- parseRequest "POST http://localhost:12777"
        let request = initialRequest
                { requestBody = RequestBodyLBS (BSC.pack (show i))
                }
        forkIO $ do
            response <- liftResourceT (http request manager)
            liftResourceT (responseBody response `connect` sinkNull)

What am I doing wrong? Or is it a bug in http-client?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions