hs-connection icon indicating copy to clipboard operation
hs-connection copied to clipboard

Connection-0.2.6 breaks Amazonka (stackage lts-6.12 on up)

Open dysinger opened this issue 9 years ago • 17 comments

I tracked this down over the last full day of pulling my hair. It was not unlike the bug seen in hs-tls 1.3.4 where you would get bad mac every once in a while.

With connection-0.2.5 I can pound away on amazonka. With connection-0.2.6 I get random bad mac errors.

user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624                               
.....................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  3.27s user 0.99s system 20% cpu 21.052 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
........................................................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  5.08s user 1.31s system 11% cpu 56.224 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
........................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  3.28s user 0.95s system 17% cpu 24.207 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
............................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  3.15s user 0.87s system 14% cpu 27.544 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
.........................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  3.27s user 0.75s system 15% cpu 25.356 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
.................................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  3.18s user 1.00s system 12% cpu 33.218 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
..................................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  2.50s user 1.00s system 10% cpu 34.065 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
........................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  2.58s user 0.75s system 13% cpu 24.302 total
user@computer:~/src/github.com/fpco/ops% time stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624
........................ops: TransportError (TlsExceptionHostPort (Terminated True "received fatal error: BadRecordMac" (Error_Protocol ("remote side fatal error",True,BadRecordMac))) "s3.amazonaws.com" 443)
stack exec -- ops aws s3 purge 222b3ebc-70a0-11e6-80be-0f425a3fa624  2.22s user 0.84s system 12% cpu 24.030 total

dysinger avatar Sep 02 '16 18:09 dysinger

lts-6.11 completes without error for my project

% diff <(stack --resolver=lts-6.11 list-dependencies) <(stack --resolver=lts-6.12 list-dependencies) 
43c43
< connection 0.2.5
---
> connection 0.2.6

dysinger avatar Sep 02 '16 18:09 dysinger

Sorry for your hair ! could you try with the latest cryptonite commit 8908af32168f6676b8f98b509ab5376706ab5660 to see if that works for you ?

vincenthz avatar Sep 02 '16 20:09 vincenthz

My hair is ok :) Here's a script that will reproduce

#!/usr/bin/env stack
-- stack --resolver lts-6.12 --install-ghc runghc --package conduit --package lens --package amazonka --package amazonka-s3

{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Lens
import Control.Monad.IO.Class
import Data.Conduit
import qualified Data.Conduit.List as CL
import Data.Monoid
import Data.String
import Data.Foldable
import Data.Text (Text)
import qualified Data.Text.IO as TI
import Network.AWS
import Network.AWS.Data
import Network.AWS.S3

main = do
    env <- newEnv NorthVirginia Discover
    let say = liftIO . TI.putStrLn
        val
            :: ToText a
            => Maybe a -> Text
        val = maybe "Nothing" toText
        lat v = maybe mempty (mappend " - " . toText) (v ^. ovIsLatest)
        key v = val (v ^. ovKey) <> ": " <> val (v ^. ovVersionId) <> lat v
    runResourceT . runAWS env $
        do say "Listing Buckets .."
           bs <- view lbrsBuckets <$> send listBuckets
           say $ "Found " <> toText (length bs) <> " Buckets."
           forM_ bs $
               \(view bName -> b) -> do
                   say $ "Listing Object Versions in: " <> toText b
                   paginate (listObjectVersions b) =$=
                       CL.concatMap (view lovrsVersions) $$
                       CL.mapM_ (say . mappend " -> " . key)

Run it against any AWS account with some buckets & objects. After about 30 seconds or so it'll crash.

dysinger avatar Sep 03 '16 01:09 dysinger

change the script to lts-6.11 and it'll work fine

dysinger avatar Sep 03 '16 01:09 dysinger

I wonder if this is related to https://github.com/erikd-ambiata/test-warp-wai/issues/1#issuecomment-244352535 ?

erikd avatar Sep 04 '16 07:09 erikd

Looks similar @erikd

dysinger avatar Sep 06 '16 16:09 dysinger

https://github.com/snoyberg/http-client/issues/225

dysinger avatar Sep 06 '16 16:09 dysinger

dysinger: I'm not sure how to test this script with a non-released version of cryptonite, any idea ?

vincenthz avatar Sep 10 '16 15:09 vincenthz

I've tried recreating my issue just using the connection library talking to HTTP and HTTPS servers. Was not able to find anything, suggesting that this was actually a problem with http-client.

erikd avatar Sep 13 '16 01:09 erikd

@erikd: I don't think that's the case, definitely a low level crypto issue. did you use the git version of cryptonite ?

vincenthz avatar Sep 13 '16 06:09 vincenthz

Nope, used the 0.19 release version.

erikd avatar Sep 13 '16 06:09 erikd

@erikd I don't think you have the same issue than @dysinger here, this is the BadRecordMac issue

vincenthz avatar Sep 13 '16 07:09 vincenthz

Ah ok, may be a different issue.

erikd avatar Sep 13 '16 08:09 erikd

is this still a bug ? (both connection and tls has new revisions since)

vincenthz avatar Mar 14 '17 10:03 vincenthz

Its still a HANDLE leak as far as I can tell. I tried it with connection 2.7 about a month ago.

I can test again (tomorrow) if you let me know what versions I should be testing.

erikd avatar Mar 14 '17 10:03 erikd

that sounds like a different bug from the BadRecordMac

vincenthz avatar Mar 14 '17 10:03 vincenthz

Opened #29 .

erikd avatar Mar 15 '17 00:03 erikd