Skip to content

Commit

Permalink
fixes #1230 NNG_OPT_RECONNMAXT zero does not prevent exponential back…
Browse files Browse the repository at this point in the history
…-off
  • Loading branch information
gdamore committed May 24, 2020
1 parent 6f084d8 commit d2146d6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,26 +1375,28 @@ nni_ctx_setopt(
static void
dialer_timer_start_locked(nni_dialer *d)
{
nni_duration backoff;
nni_duration back_off;
nni_sock * sock = d->d_sock;

if (d->d_closing || sock->s_closed) {
return;
}
backoff = d->d_currtime;
d->d_currtime *= 2;
if ((d->d_maxrtime > 0) && (d->d_currtime > d->d_maxrtime)) {
d->d_currtime = d->d_maxrtime;
back_off = d->d_currtime;
if (d->d_maxrtime > 0) {
d->d_currtime *= 2;
if (d->d_currtime > d->d_maxrtime) {
d->d_currtime = d->d_maxrtime;
}
}

// To minimize damage from storms, etc., we select a backoff
// value randomly, in the range of [0, backoff-1]; this is
// pretty similar to 802 style backoff, except that we have a
// To minimize damage from storms, etc., we select a back-off
// value randomly, in the range of [0, back_off-1]; this is
// pretty similar to 802 style back-off, except that we have a
// nearly uniform time period instead of discrete slot times.
// This algorithm may lead to slight biases because we don't
// have a statistically perfect distribution with the modulo of
// the random number, but this really doesn't matter.
nni_sleep_aio(backoff ? nni_random() % backoff : 0, d->d_tmo_aio);
nni_sleep_aio(back_off ? nni_random() % back_off : 0, d->d_tmo_aio);
}

void
Expand Down

0 comments on commit d2146d6

Please sign in to comment.