<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://reviewboard.asterisk.org/r/4071/">https://reviewboard.asterisk.org/r/4071/</a>
</td>
</tr>
</table>
<br />
<table bgcolor="#e0e0e0" width="100%" cellpadding="8" style="border: 1px gray solid;">
<tr>
<td>
<h1 style="margin-right: 0.2em; padding: 0; font-size: 10pt;">This change has been marked as submitted.</h1>
</td>
</tr>
</table>
<br />
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for Asterisk Developers, Matt Jordan and Mark Michelson.</div>
<div>By Jonathan Rose.</div>
<p style="color: grey;"><i>Updated Oct. 14, 2014, 1:49 p.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Changes</h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Committed in revision 425503</pre>
</td>
</tr>
</table>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>
<a href="https://issues.asterisk.org/jira/browse/ASTERISK-24321">ASTERISK-24321</a>
</div>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This issue was discovered by a rather complicated series of tests by PQ and it's somewhat intermittent relying on hitting the same race conditions that were being solved by r422070. When this problem hits the __sip_ack method in chan_sip in particular, things go south quickly.
The gist of it is that when we attempt to remove an existing task, we mark it for deletion and it is later removed from the scheduler. The deleted entry doesn't get free'd on account of the scheduler caching task structures so that we don't waste a bunch of effort reallocating all of the task structures every time a task needs to be created/torn down. When we wanted to remove a task that was currently executing, we couldn't do this immediately so we would apply a deleted flag. Unfortunately we didn't bother to clear the deleted flag when pulling it back off of the cache to create a new task. Oops. In any event, shenanigans ensued because the new task would be created already doomed and while they would be reported as successfully scheduled, ast_sched_runq would immediately delete the new task without replacing it the chan_sip __sip_ack function was anticipating that the tasks would stick around until it deleted them.
The fix is mind-numbingly simple for how long it took to me to figure out what the heck was going on... just remember to clear the deleted flag from scheduler entries when pulling them off the cache.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">We had a series of tests that, pre-patch would yield an assertion looking like the following:
[Oct 10 13:12:57] ERROR[18046][C-0000000e]: chan_sip.c:4428 __sip_ack: FRACK!, Failed assertion s != NULL, id=1570 (0)
Got 14 backtrace records
#0: [0x823d4fa] asterisk(__ast_assert_failed+0x7b) [0x823d4fa]
#1: [0x81fe913] asterisk(_ast_sched_del+0x2b3) [0x81fe913]
#2: [0xfeb248] /usr/lib/asterisk/modules/chan_sip.so [0xfeb248]
#3: [0x106c930] /usr/lib/asterisk/modules/chan_sip.so [0x106c930]
#4: [0x106d1e9] /usr/lib/asterisk/modules/chan_sip.so [0x106d1e9]
#5: [0x106cdb4] /usr/lib/asterisk/modules/chan_sip.so [0x106cdb4]
#6: [0x8171359] asterisk(ast_io_wait+0x14d) [0x8171359]
#7: [0x106f0f8] /usr/lib/asterisk/modules/chan_sip.so [0x106f0f8]
#8: [0x82399d5] asterisk [0x82399d5]d an infinite loop in the do_monitor thread couple with this set of log messages:
indicating that we were anticipating to find a scheduler entry that wasn't in the scheduler
Similar assertions occurred from other modules that involved schedulers but no chan_sip, but those didn't clearly break the world.
Typically a walk through the specified tests (which involved lots of chan_sip calls entering queues and lots of reloading of chan_sip and app_queue) would cause this breakdown to occur within one or two walks across the test series suggested. After performing the full set of tests 5 times each across Asterisk on two separate occasions without seeing any assertions of this type and without having chan_sip break down, I retested without the patch and quickly ran into the problem again. I think it's safe to say that I got it.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/branches/12/main/sched.c <span style="color: grey">(425241)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/4071/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>