jaspervdj / websockets

A Haskell library for creating WebSocket-capable servers
http://jaspervdj.be/websockets
BSD 3-Clause "New" or "Revised" License
407 stars 113 forks source link

sendBinaryData freezes on large (10 MB) payloads when simultaneously listening on the connection #178

Open kustosz opened 6 years ago

kustosz commented 6 years ago

Hey,

I've just stumbled upon a very strange issue with the WS server. I have found this in my production app, but shaved it down to a small repro. This code:

{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Network.WebSockets    as WS
import qualified Data.ByteString.Char8 as BS
import Control.Concurrent              (forkIO)
import Data.Traversable
import Control.Monad (forever)

main = WS.runServer "127.0.0.1" 34345 $ \pending -> do
    conn <- WS.acceptRequest pending

    forkIO $ do
        (msg :: BS.ByteString) <- WS.receiveData conn
        return ()

    WS.sendBinaryData conn $ BS.pack "hello"
    let size = 10000000
        !d = BS.pack $ take size $ cycle "hello"
    putStrLn "sending"
    WS.sendBinaryData conn d
    putStrLn "sent"

just freezes on WS.sendBinaryData (i.e. right after printing sending). A few additional remarks:

Have you ever seen similar behavior? Is there any more information I can provide for this issue?

kustosz commented 6 years ago

I don't know how this got closed, probably automatically after I've closed a PR in my own project mentioning this one. Just confirming the issue still stands.

jaspervdj commented 6 years ago

Oh, I was wondering why this was closed. I don't have a macbook so unfortunately I can't reproduce this right now, hopefully someone else steps up.

domenkozar commented 10 months ago

Would be great to have a test case, we run CI on macOS so it should reproduce.