From a124937f0c84678251f2614315dfe022262f6e10 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 4 Dec 2019 19:32:46 +0400 Subject: [PATCH] [Core] Fix wrong sqldb initialization order causing crash on load. --- src/switch_core_sqldb.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 3752a06b23..51fde6ebdf 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -3822,6 +3822,14 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ skip: if (sql_manager.manage) { + /* Initiate switch_sql_queue_manager */ + switch_threadattr_create(&thd_attr, sql_manager.memory_pool); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME); + switch_core_sqldb_start_thread(); + switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool); + + /* switch_sql_queue_manager initiated, now we can bind to core_event_handler */ #ifdef SWITCH_SQL_BIND_EVERY_EVENT switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL); #else @@ -3851,13 +3859,6 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_event_bind("core_db", SWITCH_EVENT_NAT, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL); switch_event_bind("core_db", SWITCH_EVENT_CODEC, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL); #endif - - switch_threadattr_create(&thd_attr, sql_manager.memory_pool); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME); - switch_core_sqldb_start_thread(); - switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool); - } switch_cache_db_release_db_handle(&sql_manager.dbh);