Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 107825) +++ channels/chan_sip.c (working copy) @@ -2165,7 +2165,21 @@ if (sipdebug && option_debug > 3) ast_log(LOG_DEBUG, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid); } - AST_SCHED_DEL(sched, cur->retransid); + /* This odd section is designed to thwart a + * race condition in the packet scheduler. The + * only way ast_sched_del will fail is if the packet + * is not in the scheduler queue. The only reason + * it would not be there is if the packet is currently + * being re-transmitted. If that is the case, and we + * have reached this point, then that means that retrans_pkt + * is attempting to lock p right now. So we need to + * relinquish the lock for now. + */ + while (ast_sched_del(sched, cur->retransid)) { + ast_mutex_unlock(&p->lock); + usleep(1); + ast_mutex_lock(&p->lock); + } free(cur); break; }