[Home]

Summary:ASTERISK-09674: [patch] Add AMI event generation on channel creation failure.
Reporter:Anthony (savaticus)Labels:
Date Opened:2007-06-13 14:25:59Date Closed:2007-06-22 10:28:43
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/ManagerInterface
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) rn-mod-channel.c.1.2.18.patch
( 1) rn-mod-channel.c.patch
Description:Asterisk makes a log message but does not create event messages when it fails to create a channel due to active shutdown. The reason it is a problem is because a haung channel can result in an asterisk box that will not respond until someone manually fixes the problem. I wanted the system to notify us of the issue rather than the customer. This patch corrects this problem.

At about line 517 of channel.c

Change:
____

struct ast_channel *ast_channel_alloc(int needqueue){
       struct ast_channel *tmp;
       int x;
       int flags;
       struct varshead *headp;
                      /* If shutting down, don't allocate any new channels */
       if (shutting_down) {
               ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");                
               return NULL;
       }

       tmp = malloc(sizeof(struct ast_channel));
       if (!tmp) {
               ast_log(LOG_WARNING, "Channel allocation failed: Out of memory\n");
               return NULL;
       }
       memset(tmp, 0, sizeof(struct ast_channel));
       tmp->sched = sched_context_create();        if (!tmp->sched) {
               ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"
               free(tmp);
               return NULL;
       }

________


To:

________


struct ast_channel *ast_channel_alloc(int needqueue){
       struct ast_channel *tmp;
       int x;
       int flags;
       struct varshead *headp;
                      /* If shutting down, don't allocate any new channels */
       if (shutting_down) {
               ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
                       "Cause: SHUTDOWN\r\n"
                       "Cause-txt: Channel allocation failed: Refusing due to active shutdown\r\n"
                       );
               return NULL;
       }

       tmp = malloc(sizeof(struct ast_channel));
       if (!tmp) {
               ast_log(LOG_WARNING, "Channel allocation failed: Out of memory\n");
               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
                       "Cause: OUT_OF_MEMORY\r\n"
                       "Cause-txt: Channel allocation failed: Out of memory.\r\n"
                       );
               return NULL;
       }
       memset(tmp, 0, sizeof(struct ast_channel));
       tmp->sched = sched_context_create();        if (!tmp->sched) {
               ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
                       "Cause: SCHED_CONTEXT_CREATE\r\n"
                       "Cause-txt: Channel allocation failed: Unable to create schedule context\r\n"
                       );
               free(tmp);
               return NULL;
       }

_______

I have tested this in version 1.2.14 - 1.2.17
Comments:By: Eliel Sardanons (eliel) 2007-06-13 15:09:51

Please read the bug guidelines: http://asterisk.org/developers/bug-guidelines
You should attach a diff against SVN trunk.
And you will need to fax a disclaimer too: http://www.digium.com/disclaim.changes

By: Anthony (savaticus) 2007-06-13 15:58:25

Thank you for the link. I really should have read that, I will be faxing in the disclaimer. Here is the diff output.

--- asterisk-1.2.17/channel.c   2007-02-25 07:38:03.000000000 -0700
+++ mod-asterisk-1.2.17/channel.c       2007-06-13 09:30:26.000000000 -0600
@@ -527,12 +527,20 @@
       /* If shutting down, don't allocate any new channels */
       if (shutting_down) {
               ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
+               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
+                        "Cause: SHUTDOWN\r\n"
+                        "Cause-txt: Channel allocation failed: Refusing due to active shutdown\r\n"
+                        );
               return NULL;
       }

       tmp = malloc(sizeof(struct ast_channel));
       if (!tmp) {
               ast_log(LOG_WARNING, "Channel allocation failed: Out of memory\n");
+               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
+                        "Cause: OOM\r\n"
+                        "Cause-txt: Channel allocation failed: Out of memory.\r\n"
+                        );
               return NULL;
       }

@@ -540,6 +548,10 @@
       tmp->sched = sched_context_create();
       if (!tmp->sched) {
               ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
+               manager_event(EVENT_FLAG_SYSTEM, "CHAN_FAIL",
+                        "Cause: SCC_FAIL\r\n"
+                        "Cause-txt: Channel allocation failed: Unable to create schedule context\r\n"
+                        );
               free(tmp);
               return NULL;
       }

By: Denis Smirnov (mithraen) 2007-06-14 09:37:04

savaticus, please, _attach_ this via "upload file". There not so simple reading, extracting and merging files from messages.

By: Eliel Sardanons (eliel) 2007-06-14 16:18:00

I think this is a feature and so, should be made against SVN trunk. Or at least 1.2.18

By: Anthony (savaticus) 2007-06-15 15:40:39

Faxed in the disclaimer. If anyone is using the AMI to monitor their systems and you think this state is a good one to know about without log parsing, please patch and test this!

Thank you all and have a wonderful day!

By: Russell Bryant (russell) 2007-06-22 10:28:43

I don't think this patch is something we should apply.

The first change would only occur when the administrator has requested a shutdown of the system.  Since the administrator did this, it doesn't feel useful for a manager event to reiterate this fact.

The second and third changes would only get sent if there was a memory allocation failure.  If memory allocation is failing, then Asterisk is going to blow up in many more ways, and most likely will fail in trying to generate the manager event itself, as well.

However, thank you very much for your contribution, and the patch will still be available on the bug tracker should others choose to use it.