zeromq / zmqpp

0mq 'highlevel' C++ bindings
http://zeromq.github.io/zmqpp
Mozilla Public License 2.0
438 stars 195 forks source link

Random exceptions during normal operation. #158

Closed sunkin351 closed 8 years ago

sunkin351 commented 8 years ago

The exceptions mainly revolve around sending messages, creating connections, and binding to ports. At the moment, I am heavily using sockets to connect different threads in my application over the TCP transport. I am unsure whether this is a problem with zmqpp or libzmq, and whether this is just occurring to me or if other people are also experiencing it. I am using a Windows box (Win10), and the latest source code of both (zmqpp & libzmq). Any help would be appreciated.

EDIT: Also, one thing i forgot to mention is that i first started experiencing this after I reconfigured my application to only use a single networking context for the entire program, instead of one context per thread.

xaqq commented 8 years ago

Hello,

Please (try to) provide a minimal reproducible example. Otherwise the best we can do to help is guess. So I will try to guess.

Also, one thing i forgot to mention is that i first started experiencing this after I reconfigured my application to only use a single networking context for the entire program, instead of one context per thread.

A single context for the whole application is perfectly fine, as the context object is thread-safe. However, are you using a zmqpp::socket object from multiple threads? Because this is not allowed, and will lead to bugs. You cannot write to, or read from, a socket from multiple thread.

sunkin351 commented 8 years ago

I made sure that that never happens (a single socket in multiple threads) by using class objects that spawn their own sockets. As for the example, if you can handle dozens (maybe a couple hundred even, because of the nature of multi-threaded code) of lines of code, I could try, probably would take a while.

EDIT: again, another thing i forgot to mention, most of the sockets are using the publisher-subscriber pattern. So most likely its something with libzmq...

sunkin351 commented 8 years ago

It appears I cannot recreate the conditions around why libzmq's zmq_msg_send() function returns -1 in another program. I am unsure why. I look into it during debugging and for some reason the socket object is a nullptr.

sunkin351 commented 8 years ago

This is odd... I have found a problem, but I am not sure what is causing it... In the zmqpp::socket class, the socket pointer is being reset to nullptr before I can use it.

sunkin351 commented 8 years ago

Problem found, I was trying to work against C++ scoping rules and the object my thread was working off of was being destroyed.

xaqq commented 8 years ago

Hehe trying to isolate and reproduce often lead to fixes :)