zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.62k stars 2.35k forks source link

zmq_disconnect does not work with endpoint_uri="tcp://*:5555" #4510

Open rs333 opened 1 year ago

rs333 commented 1 year ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

Calling zmq_disconnect with a uri="tcp://*:5555" does not remove the multimap _endpoints in socket_base.hpp

Environment

Visual Studio Community 2022

Minimal test code / Steps to reproduce the issue

  1. Run the following in a debugger.
#include "zmq.h"

int main (void)
{
    void *context = zmq_ctx_new ();
    void *server = zmq_socket (context, ZMQ_REP);
    zmq_bind (server, "tcp://*:5555");
    // Next line returns ENOENT from line 1208 
    // of socketbase.cpp
    zmq_disconnect(server,"tcp://*:5555");
    zmq_close (server);
    zmq_ctx_destroy (context);
    return 0;
}

What's the actual result? (include assertion message & call stack if applicable)

Line 1209 of socketbase.cpp returns after setting an error thus preventing follow on code from removing the endpoint from the map.

What's the expected result?

In the case where range.first==range.second, socketbase.cpp 1) Sees if the uri is in the _endpoints minimap 2) if so, attempts to terminate it 3) erases it from the _endpoints map 4) sets _disconnected to true 5) return 0 with no error set image image

Note

I originally question whether or not it was a valid URI. Given that it is used in the guide https://zguide.zeromq.org/docs/chapter4/ and actually works up to the point you try and disconnect, I came to the conclusion it is. Of course I could be mistaken in which case, the bug is not that it doesn't properly disconnect but it allows a connection and the docs need updated.