Domanda

First I will give you the code, then the error, then some type information. The questions are these: How can I figure out what is going on? How might I fix the problem?

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   Response _ _ _ body <-runResourceT $ http req'' manager 
   pBody <- runResourceT $
            body $$+- sinkParser json

   --   print pBody
   --   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }

This compiles fine. Here's what happens when I run the compiled code

dist/build/Spike/Spike
Spike: <socket: 3>: hGetBuf: illegal operation (handle is closed)

body is the following type

Data.Conduit.Internal.ResumableSource
(Control.Monad.Trans.Resource.ResourceT IO)
Data.ByteString.Internal.ByteString

Feedback appreciated, I don't know how to begin troubleshooting this.

È stato utile?

Soluzione

The first runResourceT call is closing the socket before the body is parsed. You will need to combine the two runResourceT calls into one. ResourceT is a Monad instance so you can use do notation and some minor surgery to free the socket after parsing is complete:

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   runResourceT $ do
      Response _ _ _ body <- http req'' manager 
      pBody <- body $$+- sinkParser json
      liftIO $ print pBody

   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top