zeromq / libzmq

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

When calling zmq_msg_recv for first time, we receive a message which has the control character 1, which is not expected. #4587

Closed zbud-msft closed 10 months ago

zbud-msft commented 11 months ago

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

Issue description

When calling zmq_msg_recv for the very first time, we are receiving message '1' with zmq_msg_size of 1. Appears to be some type of control character.

Environment

Minimal test code / Steps to reproduce the issue

template<typename DT>
int 
zmq_read_part(void *sock, int flag, int &more, DT &data)
{
    zmq_msg_t msg;

    more = 0;
    zmq_msg_init(&msg);
    int rc = zmq_msg_recv(&msg, sock, flag);
    if (rc != -1) {
        size_t more_size = sizeof (more);

        zmq_getsockopt (sock, ZMQ_RCVMORE, &more, &more_size);

        rc = zmsg_to_map(msg, data);
        RET_ON_ERR(rc == 0, "Failed to deserialize part rc=%d", rc);
        /* read more flag if message read fails to de-serialize */
    }
    else {
        /* override with zmq err */
        rc = zmq_errno();
        if (rc != 11) {
            SWSS_LOG_INFO("Failure to read part rc=%d", rc);
        }
    }
out:
    zmq_msg_close(&msg);

    return rc;
}

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

zmq_mesg_recv receives message of size1, when printed out as c_str() is "#001"

What's the expected result?

Not expected to receive any control characters.

zbud-msft commented 10 months ago

Closing this issue, control character is sent when XSUB connects to XPUB.