From c9b2d2ee68e59545c6821e1c09757804ed7628c1 Mon Sep 17 00:00:00 2001 From: Alexandr Anikin <may@telecom-service.ru> Date: Thu, 19 Dec 2013 08:15:45 +0000 Subject: [PATCH] Handle temporary failures on gk registration Introduce new 'stopped' state for gk client and restart gk client on failures Remove ooh323 stack command lock as it is not need now. (closes issue ASTERISK-21960) Reported by: Dmitry Melekhov Patches: ASTERISK-21960.patch ASTERISK-21960-stacklockup-2.patch Tested by: Dmitry Melekhov git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@404318 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- addons/chan_ooh323.c | 16 +++++++++++----- addons/ooh323c/src/ooGkClient.c | 4 ++-- addons/ooh323c/src/ooGkClient.h | 3 ++- addons/ooh323c/src/oochannels.c | 6 +----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/addons/chan_ooh323.c b/addons/chan_ooh323.c index 5f440906db..64fbcc8d28 100644 --- a/addons/chan_ooh323.c +++ b/addons/chan_ooh323.c @@ -294,8 +294,6 @@ AST_MUTEX_DEFINE_STATIC(h323_reload_lock); static int usecnt = 0; AST_MUTEX_DEFINE_STATIC(usecnt_lock); -AST_MUTEX_DEFINE_STATIC(ooh323c_cmd_lock); - static long callnumber = 0; AST_MUTEX_DEFINE_STATIC(ooh323c_cn_lock); @@ -694,7 +692,7 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca ooh323_destroy(p); ast_mutex_unlock(&iflock); return NULL; - } else if (gH323ep.gkClient && gH323ep.gkClient->state != GkClientRegistered) { + } else if (!gH323ep.gkClient || (gH323ep.gkClient && gH323ep.gkClient->state != GkClientRegistered)) { ast_log(LOG_ERROR, "Gatekeeper client is configured but not registered\n"); *cause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE; return NULL; @@ -749,7 +747,6 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca } ast_mutex_unlock(&p->lock); - ast_mutex_lock(&ooh323c_cmd_lock); ast_cond_init(&p->rtpcond, NULL); ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL); ast_mutex_lock(&p->lock); @@ -758,7 +755,6 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca } ast_mutex_unlock(&p->lock); ast_cond_destroy(&p->rtpcond); - ast_mutex_unlock(&ooh323c_cmd_lock); } restart_monitor(); @@ -3493,6 +3489,9 @@ static char *handle_cli_ooh323_show_gk(struct ast_cli_entry *e, int cmd, struct case GkClientFailed: ast_cli(a->fd, "%-20s%s\n", "GK state:", "Failed"); break; + case GkClientStopped: + ast_cli(a->fd, "%-20s%s\n", "GK state:", "Shutdown"); + break; default: break; } @@ -3918,6 +3917,13 @@ static void *do_monitor(void *data) ast_verb(1, "Reloading H.323\n"); ooh323_do_reload(); } + if (gH323ep.gkClient && gH323ep.gkClient->state == GkClientStopped) { + ooGkClientDestroy(); + ast_verb(0, "Restart stopped gatekeeper client\n"); + ooGkClientInit(gRasGkMode, (gRasGkMode == RasUseSpecificGatekeeper) ? + gGatekeeper : 0, 0); + ooGkClientStart(gH323ep.gkClient); + } /* Check for interfaces needing to be killed */ ast_mutex_lock(&iflock); diff --git a/addons/ooh323c/src/ooGkClient.c b/addons/ooh323c/src/ooGkClient.c index 3aaaba774b..af6a10bbd3 100644 --- a/addons/ooh323c/src/ooGkClient.c +++ b/addons/ooh323c/src/ooGkClient.c @@ -2851,13 +2851,13 @@ int ooGkClientHandleClientOrGkFailure(ooGkClient *pGkClient) { OOTRACEERR1("Error: Gatekeeper error detected. Closing GkClient as " "Gk mode is UseSpecifcGatekeeper\n"); - ooGkClientDestroy(); + pGkClient->state = GkClientStopped; return OO_FAILED; } else{ OOTRACEERR1("Error: Gatekeeper error detected. Closing GkClient. NEED" " to implement recovery by rediscovering another gk\n"); - ooGkClientDestroy(); + pGkClient->state = GkClientStopped; return OO_FAILED; } } diff --git a/addons/ooh323c/src/ooGkClient.h b/addons/ooh323c/src/ooGkClient.h index e12b45a962..59230e9539 100644 --- a/addons/ooh323c/src/ooGkClient.h +++ b/addons/ooh323c/src/ooGkClient.h @@ -108,7 +108,8 @@ enum OOGkClientState { GkClientRegistered, /* registered with gk */ GkClientUnregistered, GkClientGkErr,/*Gk is not responding, in discover mode can look for new GK*/ - GkClientFailed + GkClientFailed, + GkClientStopped }; diff --git a/addons/ooh323c/src/oochannels.c b/addons/ooh323c/src/oochannels.c index f581d76f99..de85389100 100644 --- a/addons/ooh323c/src/oochannels.c +++ b/addons/ooh323c/src/oochannels.c @@ -603,11 +603,7 @@ int ooProcessFDSETsAndTimers if(gH323ep.gkClient->state == GkClientFailed || gH323ep.gkClient->state == GkClientGkErr) { - if(ooGkClientHandleClientOrGkFailure(gH323ep.gkClient)!=OO_OK) - { - //ooStopMonitorCalls(); //Function calling ooProcessFDSETsAndTimers is responsible for this. - return OO_FAILED; - } + ooGkClientHandleClientOrGkFailure(gH323ep.gkClient); } } -- GitLab