public
Created

lua-zmq inverted pub-sub problem

  • Download Gist
console.log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
# Spawn receiver 1
$ lua receiver.lua &
[1] 9728
 
R 9728 init
R 9728 create socket
R 9728 bind socket
R 9728 subscribe
R 9728 before receive msg loop
 
# Spawn receiver 2
$ lua receiver.lua &
[2] 9735
 
R 9735 init
R 9735 create socket
R 9735 bind socket
R 9735 subscribe
R 9735 before receive msg loop
 
# Spawn receiver 3
$ lua receiver.lua &
[3] 9739
 
R 9739 init
R 9739 create socket
R 9739 bind socket
R 9739 subscribe
R 9739 before receive msg loop
 
# Spawn sender
$ lua sender.lua
S 9755 init
S 9755 create socket
S 9755 connect socket
S 9755 sending MSG 1
S 9755 sending MSG 2
S 9755 sending MSG 3
S 9755 close
S 9755 term
R 9739 recieved MSG 1 nil
R 9739 recieved MSG 2 nil
R 9739 recieved MSG 3 nil
R 9739 close
R 9739 term
S 9755 done
R 9739 done
[3]+ Done lua receiver.lua
 
# Spawn sender again
$ lua sender.lua
S 9759 init
S 9759 create socket
S 9759 connect socket
S 9759 sending MSG 1
S 9759 sending MSG 2
S 9759 sending MSG 3
S 9759 close
S 9759 term
 
# Sender hangs
receiver.lua
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
local posix = require 'posix'
local zmq = require 'zmq'
 
local old_print = print
local print = function(...)
print("R", posix.getpid("pid"), ...)
end
 
print("init")
local context = assert(zmq.init(1))
 
print("create socket")
local conn = assert(context:socket(zmq.SUB))
 
print("bind socket")
assert(conn:bind("ipc://tmp.ipc"))
 
print("subscribe")
assert(conn:setopt(zmq.SUBSCRIBE, ""))
 
print("before receive msg loop")
for i = 1, 3 do
print("recieved", conn:recv())
end
 
print("close")
conn:close()
conn = nil
 
print("term")
context:term()
context = nil
 
print("done")
sender.lua
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
local posix = require 'posix'
local zmq = require 'zmq'
 
local old_print = print
local print = function(...)
print("S", posix.getpid("pid"), ...)
end
 
print("init")
local context = assert(zmq.init(1))
 
print("create socket")
local conn = assert(context:socket(zmq.PUB))
 
print("connect socket")
assert(conn:connect("ipc://tmp.ipc"))
 
for i = 1, 3 do
local msg = "MSG " .. i
print("sending", msg)
assert(conn:send(msg))
end
 
print("close")
conn:close()
conn = nil
 
print("term")
context:term()
context = nil
 
print("done")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.