zmq4: Proxy error: "socket operation on non-socket"
I am trying to setup a Pub-Sub network with a proxy (like in the doc). However after a short period of time (about 1 minute) the proxy dies:
socket operation on non-socket
ctx, err := zmq.NewContext()
// frontend
s, err := ctx.NewSocket(zmq.XSUB)
if err != nil {
return fmt.Errorf("NewSocket: %s", err)
}
if err = s.Bind("inproc://input"); err != nil {
return fmt.Errorf("Bind: %s", err)
}
// backend
p, err := zmq.NewSocket(zmq.XPUB)
if err != nil {
return fmt.Errorf("NewSocket: %s", err)
}
if err = p.Bind("tcp://*:5555"); err != nil {
return fmt.Errorf("Bind: %s", err)
}
// listen
l, err := ctx.NewSocket(zmq.PAIR)
if err != nil {
return fmt.Errorf("NewSocket: %s", err)
}
if err = l.Connect("inproc://pipe"); err != nil {
return fmt.Errorf("Connect: %s", err)
}
if err := zmq.Proxy(s, p, l); err != nil {
log.Fatal("Proxy is dead: ", err)
}
And then all my publishers (each in their own thread) share the same context (ctx) and publish on inproc.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (4 by maintainers)
@kprimice I had this exact problem, the problem is that the sockets will be garbage collected by go.
Just setup a deferred call to socket.Close() and Go will keep a reference to the socket alive until your proxy is closed (by a signal)