twittner/zeromq-haskell — Issue #16: hangs or crashes when sending to socket
Author: mwotton
Created: 2012-03-07 23:31:47+00:00
State: open

import System.ZMQ as Z
import Data.Time.Clock
import Data.Time.Format()
import System.Timeout
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main = withContext 1 $ \c ->
withSocket c Req $ \s -> do
Z.connect s "tcp://127.0.0.1:5555"
forM_ [1..100] $ go s
where
go s i = do
Z.send s (BS.pack ("hi " ++ show i)) []
loggedPut i "before"
print =<< Z.receive s []
-- res <- timeout 2000000 $ Z.receive s []
-- case res of
-- Nothing -> putStrLn "Timed out"
-- Just x -> putStrLn ("worked fine: " ++ show x)

loggedPut i "after"

loggedPut i res = do
Prelude.putStr (show i ++ ": ")
Prelude.putStr . show =<< getCurrentTime
Prelude.putStrLn (": " ++ res)

when run against hwserver from the guide, this code either hangs or crashes with the message:

6: 2012-03-07 23:27:40.52898 UTC: after
7: 2012-03-07 23:27:40.529192 UTC: before
"World"
7: 2012-03-07 23:27:40.529535 UTC: after
8: 2012-03-07 23:27:40.52972 UTC: before
"World"
8: 2012-03-07 23:27:40.529947 UTC: after
9: 2012-03-07 23:27:40.530131 UTC: before
"World"
9: 2012-03-07 23:27:40.530515 UTC: after
minimal: getIntOpt: invalid argument (Socket operation on non-socket)

on occasion I get:

Assertion failed: false (zmq.cpp:304)

using zeromq-haskell 0.8.3
ghc 7.4.1
libzmq 2.1.9-1