]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] Fix wrong sqldb initialization order causing crash on load. 165/head
authorAndrey Volk <andywolk@gmail.com>
Wed, 4 Dec 2019 15:32:46 +0000 (19:32 +0400)
committerAndrey Volk <andywolk@gmail.com>
Wed, 4 Dec 2019 15:32:46 +0000 (19:32 +0400)
src/switch_core_sqldb.c

index 3752a06b2340472a28d12f446b8f724484c1fda0..51fde6ebdf745e6cfad7c411919297acefdefcf6 100644 (file)
@@ -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);