<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10189">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
George Joseph: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis: No need to keep a stasis type ref in a stasis msg or cache object.<br><br>Stasis message types are global ao2 objects and we make stasis messages<br>and cache entries hold references to them. Since there are currently<br>situations where cache objects are never deleted, the reference count on<br>the types can exceed 100000 and generate a FRACK assertion message. The<br>stasis message cache could conceivably also have that many messages<br>legitimately on large systems.<br><br>The only down side to not holding the message type ref in the stasis<br>message is it only makes a crash either at shutdown or when manually<br>unloading a busy module slightly more likely. However, this is more<br>exposing a pre-existing stasis shutdown ordering issue than a problem with<br>not holding a message type ref in stasis messages.<br><br>* Made stasis messages and cache entries no longer hold a ref to the<br>message type.<br><br>Change-Id: Ibaa28efa8d8ad3836f0c65957192424c7f561707<br>---<br>M main/stasis_cache.c<br>M main/stasis_message.c<br>2 files changed, 18 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/stasis_cache.c b/main/stasis_cache.c</span><br><span>index 3e2ab17..46bcb77 100644</span><br><span>--- a/main/stasis_cache.c</span><br><span>+++ b/main/stasis_cache.c</span><br><span>@@ -158,7 +158,6 @@</span><br><span> struct stasis_cache_entry *entry = obj;</span><br><span> size_t idx;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(entry->key.type);</span><br><span> entry->key.type = NULL;</span><br><span> ast_free((char *) entry->key.id);</span><br><span> entry->key.id = NULL;</span><br><span>@@ -206,7 +205,16 @@</span><br><span> ao2_cleanup(entry);</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- entry->key.type = ao2_bump(type);</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Normal ao2 ref counting rules says we should increment the message</span><br><span style="color: hsl(120, 100%, 40%);">+ * type ref here and decrement it in cache_entry_dtor(). However, the</span><br><span style="color: hsl(120, 100%, 40%);">+ * stasis message snapshot is cached here, will always have the same type</span><br><span style="color: hsl(120, 100%, 40%);">+ * as the cache entry, and can legitimately cause the type ref count to</span><br><span style="color: hsl(120, 100%, 40%);">+ * hit the excessive ref count assertion. Since the cache entry will</span><br><span style="color: hsl(120, 100%, 40%);">+ * always have a snapshot we can get away with not holding a ref here.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(type == stasis_message_type(snapshot));</span><br><span style="color: hsl(120, 100%, 40%);">+ entry->key.type = type;</span><br><span> cache_entry_compute_hash(&entry->key);</span><br><span> </span><br><span> is_remote = ast_eid_cmp(&ast_eid_default, stasis_message_eid(snapshot)) ? 1 : 0;</span><br><span>diff --git a/main/stasis_message.c b/main/stasis_message.c</span><br><span>index cd873f6..ef03d13 100644</span><br><span>--- a/main/stasis_message.c</span><br><span>+++ b/main/stasis_message.c</span><br><span>@@ -112,7 +112,6 @@</span><br><span> static void stasis_message_dtor(void *obj)</span><br><span> {</span><br><span> struct stasis_message *message = obj;</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_cleanup(message->type);</span><br><span> ao2_cleanup(message->data);</span><br><span> }</span><br><span> </span><br><span>@@ -131,7 +130,14 @@</span><br><span> }</span><br><span> </span><br><span> message->timestamp = ast_tvnow();</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(type, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * XXX Normal ao2 ref counting rules says we should increment the message</span><br><span style="color: hsl(120, 100%, 40%);">+ * type ref here and decrement it in stasis_message_dtor(). However, the</span><br><span style="color: hsl(120, 100%, 40%);">+ * stasis message could be cached and legitimately cause the type ref count</span><br><span style="color: hsl(120, 100%, 40%);">+ * to hit the excessive ref count assertion. Since the message type</span><br><span style="color: hsl(120, 100%, 40%);">+ * practically has to be a global object anyway, we can get away with not</span><br><span style="color: hsl(120, 100%, 40%);">+ * holding a ref in the stasis message.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> message->type = type;</span><br><span> ao2_ref(data, +1);</span><br><span> message->data = data;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10189">change 10189</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10189"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ibaa28efa8d8ad3836f0c65957192424c7f561707 </div>
<div style="display:none"> Gerrit-Change-Number: 10189 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>