[asterisk-commits] rmudgett: branch certified-13.1 r431494 - in /certified/branches/13.1: ./ apps/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 30 11:53:57 CST 2015


Author: rmudgett
Date: Fri Jan 30 11:53:54 2015
New Revision: 431494

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=431494
Log:
app_agent_pool: Fix initial module load agent device state reporting.

When the app_agent_pool module initially loads there is a race condition
between the thread loading agents.conf and the device state internal
processing thread.  If the device state internal processing thread handles
the agent creation state updates before the thread that loaded agents.conf
registers the device state provider callback then the cached agent state
is "Invalid".  When a consumer module like app_queue asks for the agent state
it gets the cached "Invalid" state instead of the real state from the provider.

* Moved loading the agents.conf configuration to the last thing setup by
app_agent_pool in load_module().  Now the device state provider callback
is registered before the config is loaded so the agent creation state
updates are guaranteed to get the initial device state.

* Removed some now redundant config cleanup on error in load_config().

* Added lock protection when accessing the device state in
agent_pvt_devstate_get() and eliminated the RAII_VAR() usage.

ASTERISK-24737 #close
Reported by: Steve Pitts

Review: https://reviewboard.asterisk.org/r/4390/
........

Merged revisions 431492 from http://svn.asterisk.org/svn/asterisk/branches/13

Modified:
    certified/branches/13.1/   (props changed)
    certified/branches/13.1/apps/app_agent_pool.c

Propchange: certified/branches/13.1/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: certified/branches/13.1/apps/app_agent_pool.c
URL: http://svnview.digium.com/svn/asterisk/certified/branches/13.1/apps/app_agent_pool.c?view=diff&rev=431494&r1=431493&r2=431494
==============================================================================
--- certified/branches/13.1/apps/app_agent_pool.c (original)
+++ certified/branches/13.1/apps/app_agent_pool.c Fri Jan 30 11:53:54 2015
@@ -552,14 +552,10 @@
 	aco_option_register(&cfg_info, "fullname", ACO_EXACT, agent_types, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct agent_cfg, full_name));
 
 	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
-		goto error;
+		return -1;
 	}
 
 	return 0;
-
-error:
-	destroy_config();
-	return -1;
 }
 
 enum agent_state {
@@ -730,12 +726,17 @@
  */
 static enum ast_device_state agent_pvt_devstate_get(const char *agent_id)
 {
-	RAII_VAR(struct agent_pvt *, agent, ao2_find(agents, agent_id, OBJ_KEY), ao2_cleanup);
-
+	enum ast_device_state dev_state = AST_DEVICE_INVALID;
+	struct agent_pvt *agent;
+
+	agent = ao2_find(agents, agent_id, OBJ_KEY);
 	if (agent) {
-		return agent->devstate;
-	}
-	return AST_DEVICE_INVALID;
+		agent_lock(agent);
+		dev_state = agent->devstate;
+		agent_unlock(agent);
+		ao2_ref(agent, -1);
+	}
+	return dev_state;
 }
 
 /*!
@@ -2641,7 +2642,7 @@
 	}
 
 	destroy_config();
-	ao2_ref(agents, -1);
+	ao2_cleanup(agents);
 	agents = NULL;
 	return 0;
 }
@@ -2655,12 +2656,6 @@
 	if (!agents) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	if (load_config()) {
-		ast_log(LOG_ERROR, "Unable to load config. Not loading module.\n");
-		ao2_ref(agents, -1);
-		agents = NULL;
-		return AST_MODULE_LOAD_DECLINE;
-	}
 
 	/* Init agent holding bridge v_table. */
 	bridge_init_agent_hold();
@@ -2686,6 +2681,13 @@
 		unload_module();
 		return AST_MODULE_LOAD_FAILURE;
 	}
+
+	if (load_config()) {
+		ast_log(LOG_ERROR, "Unable to load config. Not loading module.\n");
+		unload_module();
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list