ZMQ Pub-Sub Program Failure When Losing Network Connectivity

2024/9/8 10:50:03

I have a simple pub-sub setup on a mid-sized network, using ZMQ 2.1. Although some subscribers are using C# bindings, others are using Python bindings, and the issue I'm having is the same for either.

If I pull the network cable from a machine running a subscriber, I get an un-catchable error that immediately terminates that subscriber.

Here's a very simple example of a subscriber in Python (not actual production code, but enough to reproduce the problem):

import zmqdef main(server_address, port):context = zmq.Context()sub_socket = context.socket(zmq.SUB)sub_socket.connect("tcp://" + server_address + ":" + str(port))sub_socket.setsockopt(zmq.SUBSCRIBE, "KITH1S2")while True:msg = sub_socket.recv()      print msg  if __name__ == "__main__": main("company-intranet", 4000)

In C# the program simply terminates silently. In Python I at least get this:

Assertion failed: rc == 0 (....\src\zmq_connector.cpp:48)

This application has requested the Runtime to terminate it in an unusual way.Please contact the application's support team for more information.

I've tried non-blocking versions, and poller versions, but in either case this instant termination problem persists. Is there something obvious I should be doing but I'm not? (That is, obvious to someone else :) ).

EDIT:

Found the following: https://zeromq.jira.com/browse/LIBZMQ-207

Seems as though it is/was a known issue.

That link further links to Github, where a change log for 2.1.10 has this note:

  • Fixed issue 207, assertion failure in zmq_connecter.cpp:48, when aninvalid zmq_connect() string was used, or the hostname could not beresolved. The zmq_connect() call now returns -1 in both those cases.

Although connect() does indeed throw an Invalid Argument exception in Python (not C# apparently?), recv() still fails. If the subscriber machine suddenly loses the network, that subscriber will simply stop functioning.

So - I'm going to try using IP addresses instead of named addresses to see if this will bypass the issue. Not ideal, but better than insta-crash.

Answer

Original question: Is there something obvious I should be doing but I'm not?

No.

The workaround for now is to use IP addressing. This does not cause program failure upon network disconnect for ZMQ 2.1.x.

https://en.xdnf.cn/q/73289.html

Related Q&A

replacing html tags with BeautifulSoup

Im currently reformatting some HTML pages with BeautifulSoup, and I ran into bit of a problem.My problem is that the original HTML has things like this:<li><p>stff</p></li>and &…

LightGBM: train() vs update() vs refit()

Im implementing LightGBM (Python) into a continuous learning pipeline. My goal is to train an initial model and update the model (e.g. every day) with newly available data. Most examples load an alread…

GTK: create a colored regular button

How do I do it? A lot of sites say I can just call .modify_bg() on the button, but that doesnt do anything. Im able to add an EventBox to the button, and add a label to that, and then change its color…

How to Normalize similarity measures from Wordnet

I am trying to calculate semantic similarity between two words. I am using Wordnet-based similarity measures i.e Resnik measure(RES), Lin measure(LIN), Jiang and Conrath measure(JNC) and Banerjee and P…

How to open chrome developer console using Selenium in Python?

I am trying to open developer console in chrome using selenium webdriver. I am doingfrom selenium import webdriverfrom selenium.webdriver.common import action_chains, keys...browser = webdriver.Chrome(…

How to enable an allow-insecure-localhost flag in Chrome from selenium?

I want to enable "allow-insecure-localhost" flag from selenium. How I can do it?selenium: 3.12.0, Python:3.6.5Chrome driver creation code:def create_driver():options = Options()if sys.plat…

Getting pandas dataframe from list of nested dictionaries

I am new to Python so this may be pretty straightforward, but I have not been able to find a good answer for my problem after looking for a while. I am trying to create a Pandas dataframe from a list o…

Seaborn catplot combined with PairGrid

I am playing with the Titanic dataset, and trying to produce a pair plot of numeric variables against categorical variables. I can use Seaborns catplot to graph a plot of one numeric variable against o…

Control individual linewidths in seaborn heatmap

Is it possible to widen the linewidth for sepcific columns and rows in a seaborn heatmap?For example, can this heatmapimport numpy as np; np.random.seed(0) import seaborn as sns; sns.set() uniform_dat…

openerp context in act_window

In OpenERP 6.1 this act_window:<act_windowdomain="[(id, =, student)]"id="act_schedule_student"name="Student"res_model="school.student"src_model="school.s…