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

Problem: timers are called twice if they change the pollset #1995

Merged
merged 2 commits into from
Feb 9, 2019

Conversation

sphaero
Copy link
Contributor

@sphaero sphaero commented Feb 9, 2019

Solution:

  • first delete timers to delete then break
  • move rc==-1 check to beginning of loop to prevent the loop from not breaking

Here's a small test program which reproduces the problem:

#include "czmq.h"

static
int timer_end(zloop_t *loop, int timer_id, void *args) {
    zloop_reader_end( loop, (zsock_t *)args);
    return -1;
}

int socket_event(zloop_t *loop, zsock_t *handle, void *args)
{
    zmsg_t *msg = zmsg_recv(handle);
    zsys_notice( "Main sockect event: %s", zmsg_popstr( msg ));
    zmsg_destroy(&msg);
    return -1;
}

int main (void) {
    zsys_init();

    zloop_t *loop = zloop_new ();
    assert (loop);
    zloop_set_verbose (loop, true);

    //add a socket
    zsock_t *pub = zsock_new_pair("inproc://bla");
    int rc = zloop_reader( loop, pub, socket_event, pub);
    assert(rc == 0);
    zloop_timer(loop, 1000, 1, timer_end, pub);
    zstr_send(pub, "Test");
    zloop_start(loop);
    zsys_notice("loop ended");
    zloop_destroy(&loop);
    zsock_destroy(&pub);
    return 0;
}

it outputs:

D: 19-02-09 13:02:10 zloop: register PAIR reader
D: 19-02-09 13:02:10 zloop: register timer id=1 delay=1000 times=1
D: 19-02-09 13:02:10 zloop polling for 1000 msec
D: 19-02-09 13:02:11 zloop: call timer handler id=1
D: 19-02-09 13:02:11 zloop: cancel PAIR reader
D: 19-02-09 13:02:11 zloop polling for 0 msec
D: 19-02-09 13:02:11 zloop: call timer handler id=1
D: 19-02-09 13:02:11 zloop: cancel PAIR reader
N: 19-02-09 13:02:11 loop ended

which clearly shows the timer handler being called twice while we registered it as only to be called once

@sphaero sphaero changed the title Problem: timers are called twice if they change the pollsetf Problem: timers are called twice if they change the pollset Feb 9, 2019
@sappo sappo merged commit e85d74e into zeromq:master Feb 9, 2019
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

Successfully merging this pull request may close these issues.

2 participants