Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kustosz opened this issue Jun 2, 2018 · 3 comments
Labels

Comments

@kustosz
Copy link

kustosz commented Jun 2, 2018

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:

  • for the other side of the test, I'm using the following simple piece of JS pasted in Chrome console: a = new WebSocket("ws://127.0.0.1:34345"); a.binaryType = "arraybuffer"; a.addEventListener("message", function (e) { console.log(e.data.byteLength) });
  • removing the WS.receiveData call fixes the problems and allows me to send even larger (up to 1GB) payloads without any trouble.
  • decreasing the payload size from 10MB to 1MB fixes the problem and the code works just fine.
  • this is reproducible on a macbook pro running on macOS Sierra. I have tested it on a linux (Gentoo) machine, where the code works fine.
  • I have tried replacing the discouraged WS.runServer with Snap, that did not change anything.
  • It seems like some kind of a deadlock – memory usage jumps to 267M and no CPU is used.

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

@kustosz kustosz closed this as completed Jun 6, 2018
@kustosz
Copy link
Author

kustosz commented Jun 11, 2018

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.

@kustosz kustosz reopened this Jun 11, 2018
@jaspervdj
Copy link
Owner

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 domenkozar added the bug label Dec 29, 2023
@domenkozar
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants