From 27eb7cc704ea24e63b4ac863b14ff15cf4024136 Mon Sep 17 00:00:00 2001 From: Kevin Harwell Date: Tue, 31 Dec 2013 21:26:00 +0000 Subject: [PATCH] cel_pgsql: deadlock on unload and core_event_dispatcher A deadlock can happen between a thread unloading or reloading the cel_pgsql module and the core_event_dispatcher taskprocessor thread. Description of what is happening: Thread 1 (for example, a netconsole thread): a "module reload cel_pgsql" is launched the thread enter the "my_unload_module" function (cel_pgsql.c) the thread acquire the write lock on psql_columns the thread enter the "ast_event_unsubscribe" function (event.c) the thread try to acquire the write lock on ast_event_subs[sub->type] Thread 2 (core_event_dispatcher taskprocessor thread): the taskprocessor pop a CEL event the thread enter the "handle_event" function (event.c) the thread acquire the read lock on ast_event_subs[sub->type] the thread callback the "pgsql_log" function (cel_pgsql.c), since it's a subscriber of CEL events the thread try to acquire a read lock on psql_columns (closes issue ASTERISK-22854) Reported by: Etienne Lessard Patches: cel_pgsql_fix_deadlock_event.patch uploaded by hexanol (license 6394) ........ Merged revisions 404603 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@404604 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- cel/cel_pgsql.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c index 5885a1d32b..614a377e4d 100644 --- a/cel/cel_pgsql.c +++ b/cel/cel_pgsql.c @@ -345,11 +345,12 @@ ast_log_cleanup: static int my_unload_module(void) { struct columns *current; - AST_RWLIST_WRLOCK(&psql_columns); + if (event_sub) { event_sub = ast_event_unsubscribe(event_sub); - event_sub = NULL; } + + AST_RWLIST_WRLOCK(&psql_columns); if (conn) { PQfinish(conn); conn = NULL; -- 2.47.2