[Asterisk-code-review] taskprocessor.c: Prevent crash on graceful shutdown (asterisk[16])
Michael Bradeen
asteriskteam at digium.com
Wed Feb 2 19:18:46 CST 2022
Michael Bradeen has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17955 )
Change subject: taskprocessor.c: Prevent crash on graceful shutdown
......................................................................
taskprocessor.c: Prevent crash on graceful shutdown
When tps_shutdown is called as part of the cleanup process there is a
chance that one of the taskprocessors that references the
tps_singletons object is still running. The change is to allow for
tps_shutdown to check tps_singleton's container count and give the
running taskprocessors a chance to finish. If after 10 seconds there
are still container references we shutdown anyway as this is most
likely a bug due to a taskprocessor not being unreferenced.
ASTERISK-29365
Change-Id: Ia932fc003d316389b9c4fd15ad6594458c9727f1
---
M main/taskprocessor.c
1 file changed, 23 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/17955/1
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index 0209852..cbfa366 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -290,6 +290,29 @@
*/
static void tps_shutdown(void)
{
+ struct timespec delay = {1,0};
+ int objcount, tries=0;
+ objcount = ao2_container_count(tps_singletons);
+ /* look for taskprocessors that still have a reference to tps_singletons */
+ if (objcount>0) {
+ ast_log(LOG_WARNING,
+ "taskprocessor shutdown with %d tps object still allocated.\n", objcount);
+ }
+
+ /* give the running taskprocessors a chance to finish up */
+ while(objcount > 0 && tries < 10){
+ while(nanosleep(&delay, &delay));
+ tries++;
+ objcount = ao2_container_count(tps_singletons);
+ }
+
+ /* rather than try forever, risk an assertion on shutdown. This probably indicates
+ * a taskprocessor was not cleaned up somewhere */
+ if(objcount > 0){
+ ast_log(LOG_ERROR,
+ "taskprocessor shutdown while tasks still runing, assertion may occur!\n");
+ }
+
ast_cli_unregister_multiple(taskprocessor_clis, ARRAY_LEN(taskprocessor_clis));
AST_VECTOR_CALLBACK_VOID(&overloaded_subsystems, ast_free);
AST_VECTOR_RW_FREE(&overloaded_subsystems);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17955
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ia932fc003d316389b9c4fd15ad6594458c9727f1
Gerrit-Change-Number: 17955
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220202/1e6b0a2e/attachment.html>
More information about the asterisk-code-review
mailing list