You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a crash when using ZeroMQ, specifically within the zmq::msg_t::data function as it's called by zmq::xsub_t::match. Below is the backtrace captured with GDB, which shows the program aborting after a failed assertion check in ZeroMQ's error handling.
class ZmqSubscriber {
public:
ZmqSubscriber() {}
// Initialization function, creates sockets in the main thread
int init() {
ZmqContext::ctx_lock();
// Subscriber socket created in the main thread
_subscriber = zmq::socket_t(_zmq_context, ZMQ_SUB);
_subscriber.setsockopt(ZMQ_SNDHWM, 8192);
_subscriber.setsockopt(ZMQ_RCVHWM, 8192);
_subscriber.setsockopt(ZMQ_LINGER, 0);
std::stringstream proc_ss;
uint64_t this_p = (uint64_t)this;
proc_ss << "inproc://event_" << this_p;
// Event publisher socket created in the main thread
_event_pub = zmq::socket_t(*ZmqContext::instance()->ctx(), ZMQ_PUB);
_event_pub.bind(proc_ss.str());
// Event subscriber socket created in the main thread
_event_sub = zmq::socket_t(*ZmqContext::instance()->ctx(), ZMQ_SUB);
_event_sub.connect(proc_ss.str());
_event_sub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
_event_sub.setsockopt(ZMQ_LINGER, 0);
ZmqContext::ctx_unlock();
_running = true;
// Listener thread started for asynchronous processing
_listen_thread = os::Thread(&ZmqSubscriber::listen_thread, this);
return 0;
};
int release() {
if (_running) {
_running = false;
if (_listen_thread.joinable()) {
_listen_thread.join();
}
_subscriber.close();
_event_pub.close();
_event_sub.close();
}
return 0;
};
private:
// Background listener thread to handle all incoming events
void listen_thread() {
zmq::pollitem_t zmq_pool_item[] = {{_subscriber, 0, ZMQ_POLLIN, 0},
{_event_sub, 0, ZMQ_POLLIN, 0}};
while (_running) {
try {
int rc = zmq::poll(zmq_pool_item, 2, 100);
if (rc < 0) {
continue;
}
if (zmq_pool_item[0].revents & ZMQ_POLLIN) {
process_msg(); // Process received messages
}
if (zmq_pool_item[1].revents & ZMQ_POLLIN) {
process_event(); // Process received events
}
} catch (const std::exception &e) {
break;
}
}
};
void process_msg();
void process_event();
private:
zmq::socket_t _subscriber; // Subscriber socket
zmq::socket_t _event_pub; // Event publisher socket
zmq::socket_t _event_sub; // Event subscriber socket
};
In the ZmqSubscriber class, sockets are created in the main thread within the init() method. This includes a subscriber socket for receiving data, an event publisher socket for sending out events, and an event subscriber socket for receiving internal events. Each socket is configured with specific options, such as ZMQ_SNDHWM, ZMQ_RCVHWM, and ZMQ_LINGER, before being bound or connected to specific in-process endpoints.
After the sockets are set up, the listen_thread is started. This background thread is dedicated to handling all incoming events on these sockets. It continuously polls the sockets for data using zmq::poll, and processes messages or events whenever they become available.
What's the actual result? (include assertion message & call stack if applicable)
I know that sockets are not thread-safe, and I have ensured that all socket operations are handled within the listen_thread to maintain thread safety.
However, I am still experiencing aborts.
Thank you in advance for your support and assistance!
The text was updated successfully, but these errors were encountered:
Issue description
I encountered a crash when using ZeroMQ, specifically within the zmq::msg_t::data function as it's called by zmq::xsub_t::match. Below is the backtrace captured with GDB, which shows the program aborting after a failed assertion check in ZeroMQ's error handling.
Backtrace:
Minimal test code / Steps to reproduce the issue
In the ZmqSubscriber class, sockets are created in the main thread within the init() method. This includes a subscriber socket for receiving data, an event publisher socket for sending out events, and an event subscriber socket for receiving internal events. Each socket is configured with specific options, such as ZMQ_SNDHWM, ZMQ_RCVHWM, and ZMQ_LINGER, before being bound or connected to specific in-process endpoints.
After the sockets are set up, the listen_thread is started. This background thread is dedicated to handling all incoming events on these sockets. It continuously polls the sockets for data using zmq::poll, and processes messages or events whenever they become available.
What's the actual result? (include assertion message & call stack if applicable)
I know that sockets are not thread-safe, and I have ensured that all socket operations are handled within the listen_thread to maintain thread safety.
However, I am still experiencing aborts.
Thank you in advance for your support and assistance!
The text was updated successfully, but these errors were encountered: