Skip to content

zmq_ctx_shutdown has not effect before any socket is created #3792

@gummif

Description

@gummif

Issue description

Calling zmq_ctx_shutdown does not affect the sockets created after that call unless at least 1 socket has been created before the zmq_ctx_shutdown call.

This can cause threads to block forever if shutdown is called before any socket is created, but the thread creates a socket after the shutdown.

Related to zeromq/cppzmq#377

Environment

  • libzmq version (commit hash if unreleased): 4.3.2
  • OS: Linux

Minimal test code / Steps to reproduce the issue

#include <zmq.h>
#include <cassert>

int main()
{
    void* ctx = zmq_ctx_new();
    assert(ctx);
    //void* s0 = zmq_socket(ctx, ZMQ_REP); // uncomment these for ETERM in zmq_socket below
    //zmq_close(s0);
    zmq_ctx_shutdown(ctx);

    void* s = zmq_socket(ctx, ZMQ_REP);
    if (!s)
    {
        printf("zmq_socket failed: %s\n", zmq_strerror(zmq_errno()));
        return 1;
    }
    //zmq_ctx_shutdown(ctx); // uncomment this for ETERM in zmq_bind
    int rc = zmq_bind(s, "inproc://test");
    if (rc == -1)
    {
        printf("zmq_bind failed: %s\n", zmq_strerror(zmq_errno()));
        return 1;
    }
    puts("going to block");
    char b[1];
    rc = zmq_recv(s, b, 1, 0);
}

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

going to block

What's the expected result?

zmq_socket failed: Context was terminated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions