[Asterisk-code-review] app_chanisavail/cdr: ChanIsAvail sometimes fails to deactivate CDR. (asterisk[16])

Frederic LE FOLL asteriskteam at digium.com
Wed Nov 27 11:39:26 CST 2019


Frederic LE FOLL has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13310 )


Change subject: app_chanisavail/cdr: ChanIsAvail sometimes fails to deactivate CDR.
......................................................................

app_chanisavail/cdr: ChanIsAvail sometimes fails to deactivate CDR.

Retries may be necessary for CDR deactivation on temporary channel.
Temporary channel lifespan is very short and CDR deactivation request
through AST_CDR_FLAG_DISABLE_ALL flag may happen when CDR is not
available yet.

ASTERISK-28636

Change-Id: I1cbe09e8d2169c0962c1195133ff260d291f2074
---
M apps/app_chanisavail.c
1 file changed, 20 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/10/13310/1

diff --git a/apps/app_chanisavail.c b/apps/app_chanisavail.c
index 446bce1..d9a7e26 100644
--- a/apps/app_chanisavail.c
+++ b/apps/app_chanisavail.c
@@ -179,7 +179,26 @@
 					ast_str_append(&tmp_availcause, 0, "%s%s", ast_str_strlen(tmp_availcause) ? "&" : "", tmp);
 
 					/* Disable CDR for this temporary channel. */
-					ast_cdr_set_property(ast_channel_name(tempchan), AST_CDR_FLAG_DISABLE_ALL);
+					/* XXX Should this be conditioned to an option, due to performance cost? */
+					do {
+						int res;
+						int attempt;
+						const int max_attempts = 20;            /* 20 attempts max */
+						const useconds_t delay_us = 500;        /* 500µs x 20 attempts => give-up after 10ms max */
+
+						/* Retries may be necessary:
+						 * ast_cdr_set_property() may be executed too soon, before CDR is present in CDRs container.
+						 */
+						for (attempt = 1; attempt <= max_attempts && (res = ast_cdr_set_property(ast_channel_name(tempchan), AST_CDR_FLAG_DISABLE_ALL)) != 0; attempt++)
+							usleep(delay_us);
+						if (res != 0) {
+							ast_log(AST_LOG_NOTICE, "Failed to disable CDRs on channel %s\n",
+								ast_channel_name(tempchan));
+						} else if (attempt > 1) {
+							ast_debug(1, "Finally succeeded in disabling CDRs on channel %s, attempt:%d\n",
+								ast_channel_name(tempchan), attempt);
+						}
+					} while(0);
 
 					ast_hangup(tempchan);
 					tempchan = NULL;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13310
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I1cbe09e8d2169c0962c1195133ff260d291f2074
Gerrit-Change-Number: 13310
Gerrit-PatchSet: 1
Gerrit-Owner: Frederic LE FOLL <frederic.lefoll at c-s.fr>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191127/d3f4fccf/attachment-0001.html>


More information about the asterisk-code-review mailing list