Comments (7)
setting ROUTER_MANDATORY is asking for messages sent to an IDENTITY not currently connected to raise this error. This occurs when DEALERs disconnect. If you want a DEALER to have a consistent address, so that the reconnected DEALER will get messages intended for the original, set the socket's IDENTITY before connecting:
receive_socket.identity = b'something-stable-but-unique'
receive_socket.connect(...)
I think you'll still see these errors while the restarted socket has not yet reconnected, so you'll probably want your own retry logic at the application level as well, to retry messages failing with EHOSTUNREACH up to some limit or timeout.
from pyzmq.
setting ROUTER_MANDATORY is asking for messages sent to an IDENTITY not currently connected to raise this error. This occurs when DEALERs disconnect. If you want a DEALER to have a consistent address, so that the reconnected DEALER will get messages intended for the original, set the socket's IDENTITY before connecting:
receive_socket.identity = b'something-stable-but-unique' receive_socket.connect(...)I think you'll still see these errors while the restarted socket has not yet reconnected, so you'll probably want your own retry logic at the application level as well, to retry messages failing with EHOSTUNREACH up to some limit or timeout.
Yes, I forget to set zmq.IDENTITY in DEALER, but set it can't resolve Host unreachable error while restarting DEALER only, unless I catch Host unreachable error in ROUTER and rebind send_socket, is DEALER can't reconnect ROUTER itself after restart ?
from pyzmq.
I'm not sure I quite understand the question, but 'Host unreachable' will be raised if the ROUTER ever tries to send a message while the DEALER is not connected. This is a libzmq behavior question, so you're probably better off asking on libzmq instead of pyzmq, which is specifically about the Python bindings.
ROUTER_MANDATORY doesn't behave as I'd expect when an identity is re-used, and I don't know if that's a bug or not and can't really help further (I think there's a bug, but it's not in pyzmq).
I'd recommend avoiding identity re-use, and instead using a separate registration mechanism so your dealer registers itself with a request at the application-level and the router uses a {'name': b'identity'}
map to route messages.
from pyzmq.
more detail,
A simple example, just restart recv.py after, then will not receive the msg send. But netstat -anp | grep 9002
will see tcp connect between them
# send.py
import zmq
import time
ctx = zmq.Context()
send_sock = ctx.socket(zmq.ROUTER)
send_sock.bind('tcp://127.0.0.1:9002')
# send_sock.setsockopt(zmq.ROUTER_MANDATORY, 1) # if set, will raise "zmq.error.ZMQError: Host unreachable" immediately
while 1:
send_sock.send_multipart([b'1', b'ok'], zmq.NOBLOCK)
time.sleep(2)
# recv.py
import zmq
ctx = zmq.Context()
recv_sock = ctx.socket(zmq.DEALER)
recv_sock.setsockopt_string(zmq.IDENTITY, '1')
recv_sock.connect('tcp://127.0.0.1:9002')
while 1:
print(recv_sock.recv_multipart()[0])
from pyzmq.
That sounds like a libzmq bug to me, feel free to open an issue there. There's nothing to do about it in the Python bindings.
from pyzmq.
@minrk Doesn't seem like a bug zeromq/libzmq#4603 (comment)
Can you confirm?
from pyzmq.
I'm not sure what I'm confirming, if libzmq says it's not a bug, it's not a bug. I'll close here, since the libzmq report has precedence and appears to contain an explanation of how to fix it.
from pyzmq.
Related Issues (20)
- BUG: zmq.asyncio.Poller does not return POLLPRI events before timeout HOT 1
- Subscriber recieve hangs infinitely HOT 1
- Unexpected Keyword Argument 'block' HOT 1
- BUG: RTLD_GLOBAL dlopen flag causes segfaults w/ pynacl & libsodium HOT 4
- BUG: test_green_device crashes with Python 3.12 on ppc64le
- FEATURE + MR: Advertise newer python versions
- Why does the wheel package on pypi not support IPC on windows 10? HOT 2
- BUG: asyncio: memory leak in socket.poll HOT 1
- Release 25.1 with Python 3.12 wheels
- [lint] abstract class instantiated HOT 2
- BUG: Older versions of setuptools no longer work HOT 7
- BUG: windows arm64 support HOT 12
- BUG: `try_passwordless_ssh` hangs while connecting to server HOT 2
- RFE: is it possible to restart making github releases?🤔 HOT 6
- unable to build on mac m1 max HOT 11
- BUG: Missing zmq.NOTIFY_CONNECT and zmq.NOTIFY_DISCONNECT constants HOT 6
- BUG: zmq hangs forever if attempting to send a message before socket has time to connect HOT 1
- BUG: Unable to install in mac m1 HOT 1
- build fairure with cython default bnanch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyzmq.