<p>Michael Bradeen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17955">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">taskprocessor.c: Prevent crash on graceful shutdown<br><br>When tps_shutdown is called as part of the cleanup process there is a<br>chance that one of the taskprocessors that references the<br>tps_singletons object is still running. The change is to allow for<br>tps_shutdown to check tps_singleton's container count and give the<br>running taskprocessors a chance to finish. If after 10 seconds there<br>are still container references we shutdown anyway as this is most<br>likely a bug due to a taskprocessor not being unreferenced.<br><br>ASTERISK-29365<br><br>Change-Id: Ia932fc003d316389b9c4fd15ad6594458c9727f1<br>---<br>M main/taskprocessor.c<br>1 file changed, 23 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/17955/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/taskprocessor.c b/main/taskprocessor.c</span><br><span>index 0209852..cbfa366 100644</span><br><span>--- a/main/taskprocessor.c</span><br><span>+++ b/main/taskprocessor.c</span><br><span>@@ -290,6 +290,29 @@</span><br><span> */</span><br><span> static void tps_shutdown(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timespec delay = {1,0};</span><br><span style="color: hsl(120, 100%, 40%);">+ int objcount, tries=0;</span><br><span style="color: hsl(120, 100%, 40%);">+ objcount = ao2_container_count(tps_singletons);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* look for taskprocessors that still have a reference to tps_singletons */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (objcount>0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING,</span><br><span style="color: hsl(120, 100%, 40%);">+ "taskprocessor shutdown with %d tps object still allocated.\n", objcount);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* give the running taskprocessors a chance to finish up */</span><br><span style="color: hsl(120, 100%, 40%);">+ while(objcount > 0 && tries < 10){</span><br><span style="color: hsl(120, 100%, 40%);">+ while(nanosleep(&delay, &delay));</span><br><span style="color: hsl(120, 100%, 40%);">+ tries++;</span><br><span style="color: hsl(120, 100%, 40%);">+ objcount = ao2_container_count(tps_singletons);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* rather than try forever, risk an assertion on shutdown. This probably indicates</span><br><span style="color: hsl(120, 100%, 40%);">+ * a taskprocessor was not cleaned up somewhere */</span><br><span style="color: hsl(120, 100%, 40%);">+ if(objcount > 0){</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+ "taskprocessor shutdown while tasks still runing, assertion may occur!\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_cli_unregister_multiple(taskprocessor_clis, ARRAY_LEN(taskprocessor_clis));</span><br><span> AST_VECTOR_CALLBACK_VOID(&overloaded_subsystems, ast_free);</span><br><span> AST_VECTOR_RW_FREE(&overloaded_subsystems);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17955">change 17955</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/c/asterisk/+/17955"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ia932fc003d316389b9c4fd15ad6594458c9727f1 </div>
<div style="display:none"> Gerrit-Change-Number: 17955 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>