twittner/zeromq-haskell — Issue #15: poll doesn't return within (or close to) timeout
Author: mwotton
Created: 2012-03-07 03:03:51+00:00
State: open

import System.ZMQ
import Data.Time.Clock
import Data.Time.Format

main = withContext 1 $ \c ->
withSocket c XReq $ \s -> do
connect s "tcp://localhost:5555"
loggedPut "before"
res <- poll [S s In] $ 2000000
loggedPut "after"

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

Running this without a socket waiting at localhost:5555 leaves the process hanging forever in the poll. Running strace -tt on it gives this output:

13:58:10.008488 clone(child_stack=0x7f88c77f0f70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f88c77f19d0, tls=0x7f88c77f1700, child_tidptr=0x7f88c77f19d0) = 19450
13:58:10.008557 socketpair(PF_FILE, SOCK_STREAM, 0, [11, 12]) = 0
13:58:10.008596 fcntl(11, F_GETFL) = 0x2 (flags O_RDWR)
13:58:10.008624 fcntl(11, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:58:10.008651 fcntl(12, F_GETFL) = 0x2 (flags O_RDWR)
13:58:10.008677 fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:58:10.008766 socketpair(PF_FILE, SOCK_STREAM, 0, [13, 14]) = 0
13:58:10.008804 fcntl(13, F_GETFL) = 0x2 (flags O_RDWR)
13:58:10.008833 fcntl(13, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:58:10.008860 fcntl(14, F_GETFL) = 0x2 (flags O_RDWR)
13:58:10.008887 fcntl(14, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:58:10.009017 open("/dev/urandom", O_RDONLY) = 15
13:58:10.009066 fcntl(15, F_GETFD) = 0
13:58:10.009094 fcntl(15, F_SETFD, FD_CLOEXEC) = 0
13:58:10.009124 getuid() = 1000
13:58:10.009158 getppid() = 19447
13:58:10.009189 read(15, "r\377|^(\353\260\30\252\7]J\225\325\214\351", 16) = 16
13:58:10.009231 gettid() = 19448
13:58:10.009288 sendto(8, "\0", 1, 0, NULL, 0) = 1
13:58:10.009329 sendto(13, "\0", 1, 0, NULL, 0) = 1
13:58:10.009406 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
13:58:10.009684 select(2, [], [1], NULL, {0, 0}) = 1 (out [1], left {0, 0})
13:58:10.009743 write(1, "2012-03-07 02:58:10.009364 UTC: "..., 39) = 39
13:58:10.009837 poll([{fd=14, events=POLLIN}], 1, 0) = 1 ([{fd=14, revents=POLLIN}])
13:58:10.009885 poll([{fd=14, events=POLLIN}], 1, 0) = 1 ([{fd=14, revents=POLLIN}])
13:58:10.009920 recvfrom(14, "\0", 1, 0, NULL, NULL) = 1
13:58:10.009954 poll([{fd=14, events=POLLIN}], 1, 0) = 0 (Timeout)
13:58:10.009986 poll([{fd=14, events=POLLIN}], 1, 2000) = ? ERESTART_RESTARTBLOCK (To be restarted)
13:58:10.012427 --- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
13:58:10.012484 rt_sigreturn(0x1a) = -1 EINTR (Interrupted system call)
13:58:10.012551 poll([{fd=14, events=POLLIN}], 1, 0) = 0 (Timeout)
13:58:10.012630 poll([{fd=14, events=POLLIN}], 1, 0) = 0 (Timeout)
13:58:10.012697 poll([{fd=14, events=POLLIN}], 1, 2000) = ? ERESTART_RESTARTBLOCK (To be restarted)

at which point it continues to restart indefinitely.

i can give you the full strace output if it's useful, but it's about 400 lines before it starts repeating.

my system specs:

zeromq-haskell-0.8.3
libzmq-dev 2.1.9-1
ghc 7.4.1