[asterisk-commits] russell: branch 1.4 r77887 - /branches/1.4/channels/chan_iax2.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 1 17:16:17 CDT 2007
Author: russell
Date: Wed Aug 1 17:16:17 2007
New Revision: 77887
URL: http://svn.digium.com/view/asterisk?view=rev&rev=77887
Log:
Fix some race conditions which have been causing weird problems in chan_iax2.
The most notable problem is that people have been seeing storms of VNAK frames
being sent due to really old frames mysteriously being in the retransmission
queue and never getting removed.
It was possible that a dynamic thread got created, but did not acquire its lock
before the thread that created it signals it to perform an action. When this
happens, the thread will sleep until it hits a timeout, and then get destroyed.
So, the action never gets performed and in some cases, means a frame doesn't
get transmitted and never gets freed since the scheduler never gets a chance
to reschedule transmission.
Another less severe race condition is in the handling of a timeout for a dynamic
thread. It was possible for it to be acquired to perform at action at the same
time that it hit a timeout. When this occurs, whatever action it was acquired
for would never get performed.
(patch contributed by Mihai and SteveK)
(closes issue #10289)
(closes issue #10248)
(closes issue #10232)
(possibly related to issue #10359)
Modified:
branches/1.4/channels/chan_iax2.c
Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=77887&r1=77886&r2=77887
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Wed Aug 1 17:16:17 2007
@@ -715,6 +715,7 @@
time_t checktime;
ast_mutex_t lock;
ast_cond_t cond;
+ unsigned int ready_for_signal:1;
/*! if this thread is processing a full frame,
some information about that frame will be stored
here, so we can avoid dispatching any more full
@@ -900,6 +901,10 @@
} else {
/* All went well and the thread is up, so increment our count */
iaxdynamicthreadcount++;
+
+ /* Wait for the thread to be ready before returning it to the caller */
+ while (!thread->ready_for_signal)
+ usleep(1);
}
}
}
@@ -7854,11 +7859,15 @@
/* Wait for something to signal us to be awake */
ast_mutex_lock(&thread->lock);
+ /* Flag that we're ready to accept signals */
+ thread->ready_for_signal = 1;
+
/* Put into idle list if applicable */
if (put_into_idle)
insert_idle_thread(thread);
if (thread->type == IAX_TYPE_DYNAMIC) {
+ struct iax2_thread *t = NULL;
/* Wait to be signalled or time out */
tv = ast_tvadd(ast_tvnow(), ast_samp2tv(30000, 1000));
ts.tv_sec = tv.tv_sec;
@@ -7866,15 +7875,19 @@
if (ast_cond_timedwait(&thread->cond, &thread->lock, &ts) == ETIMEDOUT) {
ast_mutex_unlock(&thread->lock);
AST_LIST_LOCK(&dynamic_list);
- AST_LIST_REMOVE(&dynamic_list, thread, list);
- iaxdynamicthreadcount--;
+ /* Account for the case where this thread is acquired *right* after a timeout */
+ if ((t = AST_LIST_REMOVE(&dynamic_list, thread, list)))
+ iaxdynamicthreadcount--;
AST_LIST_UNLOCK(&dynamic_list);
- break; /* exiting the main loop */
+ if (t)
+ break; /* exiting the main loop */
}
+ if (!t)
+ ast_mutex_unlock(&thread->lock);
} else {
ast_cond_wait(&thread->cond, &thread->lock);
- }
- ast_mutex_unlock(&thread->lock);
+ ast_mutex_unlock(&thread->lock);
+ }
/* Add ourselves to the active list now */
AST_LIST_LOCK(&active_list);
More information about the asterisk-commits
mailing list