Skip to content

Commit

Permalink
Fix pinging partitioning from nat_traversal.
Browse files Browse the repository at this point in the history
Do not use the static counter as the timer routine gets executed in various processes now - better use a shm counter.
See all the details in #751
Based on the PR #751
Closing / outdating #751
Credits for finding the fix and comming up with a solutoin go to @aerringer.

(cherry picked from commit 4395575)
  • Loading branch information
bogdan-iancu committed Jan 13, 2016
1 parent 76034ad commit aa5d483
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions modules/nat_traversal/nat_traversal.c
Expand Up @@ -1655,9 +1655,14 @@ send_keepalive(NAT_Contact *contact)


static void
keepalive_timer(unsigned int ticks, void *data)
keepalive_timer(unsigned int ticks, void *counter)
{
static unsigned iteration = 0;
// we do not need to worry on accessing the counter without lock from
// all the processes where this timer routine gets executed, as the
// the routine is registered with TIMER_FLAG_DELAY_ON_DELAY and the
// timer core will take care and avoid overlapping between the executions
// of this routine (only one execution at the time)
unsigned iteration = *(unsigned*)(unsigned long*)counter;
NAT_Contact *contact;
HashSlot *slot;
time_t now;
Expand Down Expand Up @@ -1685,7 +1690,7 @@ keepalive_timer(unsigned int ticks, void *data)
}
}

iteration = (iteration+1) % keepalive_interval;
*(unsigned*)(unsigned long*)counter = (iteration+1) % keepalive_interval;
}


Expand Down Expand Up @@ -1887,7 +1892,16 @@ mod_init(void)
LM_NOTICE("using 10 seconds for keepalive_interval\n");
keepalive_interval = 10;
}
if (register_timer( "nt-pinger", keepalive_timer, NULL, 1, TIMER_FLAG_DELAY_ON_DELAY)<0) {
// allocate a shm variable to keep the counter used by the keepalive
// timer routine - it must be shared as the routine get executed
// in different processes
if (NULL==(param=(int*) shm_malloc(sizeof(int)))) {
LM_ERR("cannot allocate shm memory for keepalive counter\n");
return -1;
}
*param = 0;
if (register_timer( "nt-pinger", keepalive_timer, (void*)(long)param, 1,
TIMER_FLAG_DELAY_ON_DELAY)<0) {
LM_ERR("failed to register keepalive timer\n");
return -1;
}
Expand Down

0 comments on commit aa5d483

Please sign in to comment.