Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangs on recv when using -fsanitize=thread #4752

Open
stkw0 opened this issue Oct 31, 2024 · 0 comments
Open

Hangs on recv when using -fsanitize=thread #4752

stkw0 opened this issue Oct 31, 2024 · 0 comments

Comments

@stkw0
Copy link

stkw0 commented Oct 31, 2024

Issue description

When compiling the attached test code with g++ test.cpp -o test -lzmq -fsanitize=thread it hangs when claling to recv(). Without tsan it works correctly.

Environment

  • libzmq version (commit hash if unreleased): 4.3.5
  • cppzmq: 4.10.0
  • gcc: 14.2.1 (but it can reproduce also with clang)
  • OS: Gentoo

Minimal test code / Steps to reproduce the issue

#include <mutex>
#include <string_view>
#include <thread>
#include <iostream>

#include <zmq.hpp>

static zmq::context_t ctxt{0};

class InternalDataPub {
  public:
    InternalDataPub() {_pub.bind("inproc://cdm");}

    void publish(const std::string_view& m) {
    	    zmq::message_t msg(m.data(), m.size());
	    _pub.send(msg, zmq::send_flags::none);
    }

  private:
    zmq::socket_t _pub{ctxt, zmq::socket_type::pub};
    std::mutex _mutex;
};

class InternalDataSub {
  public:
    InternalDataSub() {_sub.connect("inproc://cdm");}

    void subscribe(const std::string_view& s ) {
	    _sub.set(zmq::sockopt::subscribe, s);
    }

    std::string recv() {
	    zmq::message_t m;
	    (void)_sub.recv(m, zmq::recv_flags::none);
	    return m.to_string();
    }

  private:
    zmq::socket_t _sub{ctxt, zmq::socket_type::sub};
};

int main() {
	auto publisher = []() {
            InternalDataPub pub;
            pub.publish("A.B.C");
        };

        std::thread t(publisher);
        InternalDataSub sub;
        sub.subscribe("A");
        std::cout << "Before recv" << std::endl;
        std::cout << sub.recv() << std::endl;
        t.join();
}

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

It just hangs without any information, crash or error

What's the expected result?

It shows the published message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant