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

ZMQ_REQ_RELAXED does not work #1690

Closed
FredTreg opened this issue Jan 1, 2016 · 1 comment
Closed

ZMQ_REQ_RELAXED does not work #1690

FredTreg opened this issue Jan 1, 2016 · 1 comment

Comments

@FredTreg
Copy link
Contributor

FredTreg commented Jan 1, 2016

The ZMQ_REQ_RELAXED option should allow you to send two messages in a row without a successful receive in between.

This does not seem to work as the simple example below (two "send" in a row) blocks indefinitely.

Note: this does not work even if the server is connected and responding.

Am I mistaken somehow?

I could track down the issue to this piece of code in req.cpp :

    if (receiving_reply) {
        if (strict) {
            errno = EFSM;
            return -1;
        }

        if (reply_pipe)
            reply_pipe->terminate(false); <-- Line causing the issue
    ...

Indeed, terminating the reply pipe also terminates the send pipe as they are the same (the pipe associated with the socket is bidirectional). Doing a terminate on the pipe sets an internal flag called out_active to false and the pipe can no longer send messages.

A simple removal of the terminateline solves the problem. Removing this line should not be an issue as the incorrect ordering of messages that could be incurred is taken care of by the ZMQ_REQ_CORRELATE option if needed.

Example code demonstrating the issue (without error handling to make it clearer):

#include "zmq.h"
#include <stdio.h>

int main (int argc, char *argv [])
{
    void *ctx;
    void *s;
    int on = 1;
    zmq_msg_t msg;

    ctx = zmq_ctx_new ();
    s = zmq_socket (ctx, ZMQ_REQ);
    zmq_setsockopt(s, ZMQ_REQ_RELAXED, &on, sizeof(int));
    zmq_connect (s, "tcp://127.0.0.1:6789");

    zmq_msg_init (&msg);
    zmq_msg_init_size (&msg, 10);
    zmq_msg_send (&msg, s, 0);
    zmq_msg_close (&msg);

    printf ("First message sent\n");

    zmq_msg_init (&msg);
    zmq_msg_init_size (&msg, 10);
    zmq_msg_send (&msg, s, 0); // <--- This line will block indefinitely
    zmq_msg_close (&msg);

    printf ("Second message sent\n");

    zmq_close (s);
    zmq_ctx_term (ctx);

    return 0;
}
FredTreg added a commit to FredTreg/libzmq that referenced this issue Jan 1, 2016
When using ZMQ_REQ_RELAXED and a 'send' is executed after another 'send' the
previous code would terminate the 'reply_pipe' if any.
This is incorrect as terminating the reply pipe also terminates the send pipe
as they are the same (a pipe associated with a socket is bidirectional).
Doing a terminate on the pipe sets an internal flag called out_active to false
and the pipe can no longer send messages.
Removing the 'terminate' solves the problem. Removing this call is not an issue
as the incorrect ordering of messages that could be incurred is taken care of
by the ZMQ_REQ_CORRELATE option if needed.
c-rack added a commit that referenced this issue Jan 1, 2016
Fixed issue #1690 (ZMQ_REQ_RELAXED)
FredTreg added a commit to FredTreg/libzmq that referenced this issue Jan 3, 2016
Current ZMQ_REQ_RELAXED test improvement to check that pipes are not closed
after executing two send() in a row with no recv() in between.
c-rack added a commit that referenced this issue Jan 3, 2016
Test for issue #1690 (ZMQ_REQ_RELAXED)
@hitstergtd
Copy link
Member

@FredTreg,
Thanks for the report. Closing issue since your pull request was merged by @c-rack.

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

2 participants