You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
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:
just freezes on
WS.sendBinaryData
(i.e. right after printingsending
). A few additional remarks:a = new WebSocket("ws://127.0.0.1:34345"); a.binaryType = "arraybuffer"; a.addEventListener("message", function (e) { console.log(e.data.byteLength) });
WS.receiveData
call fixes the problems and allows me to send even larger (up to 1GB) payloads without any trouble.WS.runServer
with Snap, that did not change anything.Have you ever seen similar behavior? Is there any more information I can provide for this issue?
The text was updated successfully, but these errors were encountered: