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

NNG_OPT_RECONNMAXT zero does not prevent exponential back-off #1230

Closed
sjpritchard opened this issue Apr 2, 2020 · 1 comment
Closed

NNG_OPT_RECONNMAXT zero does not prevent exponential back-off #1230

sjpritchard opened this issue Apr 2, 2020 · 1 comment
Assignees
Labels

Comments

@sjpritchard
Copy link

sjpritchard commented Apr 2, 2020

Firstly, thankyou for such an awesome library :)

NNG & Platform details.

  • NNG 1.3.0
  • Pair protocol using Windows IPC on Windows 10.
  • Dialer is C++ using Qt 5.14
  • Listener is C++
  • Dialer configured with NNG_FLAG_NONBLOCK
  • Dialer socket is configured with NNG_OPT_RECONNMINT=100, NNG_OPT_RECONNMAXT=0
  • Either member of the pair may start first

Expected Behavior

If the dialer is started first, it should automatically attempt to connect asynchronously to the listener every 100ms until the listener is started

Actual Behavior

If the dialer is started first, it takes between a few seconds up to nearly a minute (seems random) to connect to the listener after the listener is started. The shorter the amount of time between the dialer and listener starting, the shorter the time to connect. At a guess it's like it's doing the exponential backoff, despite the NNG_OPT_RECONNMAXT being set to 0.

If the listener is started first, the dialer connects instantly.

Steps to Reproduce

Dialer

    int rv = 0;  
    rv     = nng_pair1_open(&socket);  
    if (rv != 0) {  
        qDebug() << "NNG socket error: " << nng_strerror(rv);  
    }  
    rv = nng_socket_set_ms(socket, NNG_OPT_RECONNMINT, 100);
    rv = nng_socket_set_ms(socket, NNG_OPT_RECONNMAXT, 0);
    nng_duration socket_reconnect_minimum_time;
    nng_duration socket_reconnect_maximum_time;
    rv = nng_socket_get_ms(socket, NNG_OPT_RECONNMINT, &socket_reconnect_minimum_time);
    rv = nng_socket_get_ms(socket, NNG_OPT_RECONNMAXT, &socket_reconnect_maximum_time);
    qDebug() << "NNG socket minimum reconnect time: " << socket_reconnect_minimum_time << "ms";
    qDebug() << "NNG socket maximum reconnect time: " << socket_reconnect_maximum_time << "ms";
    rv = nng_pipe_notify(socket, NNG_PIPE_EV_ADD_POST, &nng_pipe_cb, nullptr);
    rv = nng_dial(socket, "ipc://simcortex", &dialer, NNG_FLAG_NONBLOCK);
    if (rv != 0) {
        qDebug() << "NNG dialer error: " << nng_strerror(rv);
    }

Listener

    int rv = 0;
    rv     = nng_pair1_open(&socket);
    if (rv != 0) {
        spdlog::error("nanomsg-NG socket error: {}", nng_strerror(rv));
        // Throw an erorr
    }
    spdlog::info("nanomsg-NG socket opened");
    rv = nng_listen(socket, "ipc://simcortex", NULL, 0);
    if (rv != 0) {
        spdlog::error("nanomsg-NG listener error: {}", nng_strerror(rv));
        // Throw an error
    }
    spdlog::info("nanomsg-NG listener started");
    // Start receiver thread
    auto receiver_thread = thread(&SimCortexConnector::receive, this);
    receiver_thread.detach();
@sjpritchard sjpritchard changed the title Dialer connecting asynchronously does not connect immediately if listener is started after dialer Asynchronous dialer does not connect immediately if listener is started after dialer Apr 2, 2020
@sjpritchard
Copy link
Author

sjpritchard commented Apr 2, 2020

Update: setting NNG_OPT_RECONNMAXT to the same as NNG_OPT_RECONNMINT resolves the problem. However, the documentation for NNG_OPT_RECONNMAXT states:

If this value is zero, then no exponential back-off between connection attempts is done, and each attempt will wait the time specified by NNG_OPT_RECONNMINT.

@gdamore gdamore self-assigned this May 24, 2020
@gdamore gdamore changed the title Asynchronous dialer does not connect immediately if listener is started after dialer NNG_OPT_RECONNMAXT zero does not prevent exponential back-off May 24, 2020
@gdamore gdamore added the bug label May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants