Skip to content

Commit

Permalink
unixsock: require min conn len before delay reset
Browse files Browse the repository at this point in the history
Once a unixsock obj transitions to the UP state, require the new
connection to be up for a minimum length of time before resetting
the reconnect delay.  This protects against spinning on reconnects
when the connection is immediately terminated.

Other objects using an exponential reconnect delay require the
connection to be up for at least the minimum timeout.  This doesn't
make sense for a unixsock obj which now has a 1-second minimum timeout.
Instead, unixsock uses the new MIN_CONNECT_SECS which defines the
minimum number of seconds that a newly-connected object must be up
before resetting its reconnect delay back to the minimum.
  • Loading branch information
dun committed Jun 18, 2013
1 parent 94ba7b9 commit 8c1c2a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
38 changes: 33 additions & 5 deletions server-unixsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
static int max_unixsock_dev_strlen(void);
static int connect_unixsock_obj(obj_t *unixsock);
static int disconnect_unixsock_obj(obj_t *unixsock);
static void reset_unixsock_delay(obj_t *unixsock);

extern tpoll_t tp_global; /* defined in server.c */

Expand Down Expand Up @@ -255,7 +256,12 @@ static int connect_unixsock_obj(obj_t *unixsock)
*/
unixsock->gotEOF = 0;
auxp->state = CONMAN_UNIXSOCK_UP;
auxp->delay = 0;

/* Require the connection to be up for a minimum length of time before
* resetting the reconnect-delay back to the minimum.
*/
auxp->timer = tpoll_timeout_relative(tp_global,
(callback_f) reset_unixsock_delay, unixsock, MIN_CONNECT_SECS * 1000);

/* Notify linked objs when transitioning into an UP state.
*/
Expand Down Expand Up @@ -303,13 +309,35 @@ static int disconnect_unixsock_obj(obj_t *unixsock)
}
/* Set timer for establishing new connection.
*/
auxp->delay = (auxp->delay == 0)
? UNIXSOCK_MIN_TIMEOUT
: MIN(auxp->delay * 2, UNIXSOCK_MAX_TIMEOUT);

auxp->timer = tpoll_timeout_relative(tp_global,
(callback_f) connect_unixsock_obj, unixsock,
auxp->delay * 1000);

if (auxp->delay < UNIXSOCK_MAX_TIMEOUT) {
auxp->delay = MIN(auxp->delay * 2, UNIXSOCK_MAX_TIMEOUT);
}
return(-1);
}


static void reset_unixsock_delay(obj_t *unixsock)
{
/* Resets the unixsock obj's reconnect-delay after the connection has been up
* for the minimum length of time. This protects against spinning on
* reconnects when the connection immediately terminates.
*/
unixsock_obj_t *auxp;

assert(unixsock != NULL);
assert(is_unixsock_obj(unixsock));

auxp = &(unixsock->aux.unixsock);

/* Reset the timer ID since this routine is only invoked by a timer.
*/
auxp->timer = -1;

DPRINTF((15, "Reset [%s] reconnect delay\n", unixsock->name));
auxp->delay = UNIXSOCK_MIN_TIMEOUT;
return;
}
6 changes: 4 additions & 2 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#define DEFAULT_SEROPT_PARITY 0
#define DEFAULT_SEROPT_STOPBITS 1

#define MIN_CONNECT_SECS 60

#if WITH_FREEIPMI
#define IPMI_ENGINE_CONSOLES_PER_THREAD 128
#define IPMI_MAX_USER_LEN IPMI_MAX_USER_NAME_LENGTH
Expand All @@ -72,8 +74,8 @@
#define TELNET_MAX_TIMEOUT 1800
#define TELNET_MIN_TIMEOUT 15

#define UNIXSOCK_MAX_TIMEOUT 60
#define UNIXSOCK_MIN_TIMEOUT 1
#define UNIXSOCK_MAX_TIMEOUT 60
#define UNIXSOCK_MIN_TIMEOUT 1


enum obj_type { /* type of auxiliary obj (3 bits) */
Expand Down

0 comments on commit 8c1c2a5

Please sign in to comment.