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

ParseError {errorContexts = ["demandInput"], errorMessage = "not enough bytes"} #3

Open
twittner opened this issue Jul 18, 2013 · 1 comment

Comments

@twittner
Copy link
Contributor

Given this test server:

module Main where

import Control.Exception (SomeException)
import Control.Monad
import Control.Monad.IO.Class
import Network.WebSockets
import Network.WebSockets.Snap
import Snap (quickHttpServe)

main :: IO ()
main = quickHttpServe (runWebSocketsSnap f)

f :: Request -> WebSockets Hybi10 ()
f r = do
    acceptRequest r
    catchWsError (forever $ void receiveDataMessage) printE

printE :: MonadIO m => SomeException -> m ()
printE = liftIO . print

and this example client.

Starting the server and the client establishes the connection just fine, but when the client receives a SIGINT the server logs:

an exception escaped to toplevel:
ParseError {errorContexts = ["demandInput"], errorMessage = "not enough bytes"}

This happens only before the client has sent any data messages.

@twittner
Copy link
Contributor Author

AFAICS this behavior is caused by runWebSocketsWith re-throwing iteratee exceptions. runWebSocketsSnapWith does not handle this, hence the exception reaches Snap. How about:

catchError (WS.runWebSocketsWith options' (fromSnapRequest rq) ws writeEnd)
           (const $ yield () EOF)

or some other safeguard mechanism in

in WS.runWebSocketsWith options' (fromSnapRequest rq) ws writeEnd
?

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

No branches or pull requests

1 participant