cppzmq icon indicating copy to clipboard operation
cppzmq copied to clipboard

void monitor_t::abort() is violating RAII principle

Open lp35 opened this issue 4 years ago • 2 comments

Hi,

I run into a strange bug today, due to monitor_t.

To my understanding of the class, what init() does is reversed by abort() call.

abort() should then free the socket, to allow the zmq context to be freed.

In this case, abort should contains the following code:

       if (socketPtr)
            zmq_socket_monitor(socketPtr, NULL, 0);

        socketPtr = NULL;

        if (monitor_socket)
            zmq_close(monitor_socket);

The socket cannot be closed until the destructor is called, that can be problematic for some use cases.

I guess that issue #185 is related to this bug.

EDIT: I think thix fix is not intended to be in abort() method. I suggest to create a new method, called close() that close properly the socket.

lp35 avatar Jan 27 '20 16:01 lp35

(I can PR if needed)

lp35 avatar Jan 27 '20 16:01 lp35

I am not sure if I understand the problem here completely. Shutting down monitoring right is rather tricky, unfortunately. I am currently investigating an issue in libzmq related to that as well. Could you share a test case that demonstrates the problem?

sigiesec avatar Jan 28 '20 06:01 sigiesec