diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 19d34c39b3e..6b15269f567 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -3630,6 +3630,10 @@ int syncd_main(int argc, char **argv) onSyncdStart(options.startType == SAI_WARM_BOOT); SWSS_LOG_NOTICE("after onSyncdStart"); + // create notifications processing thread after we create_switch to + // make sure, we have switch_id translated to VID before we start + // processing possible quick fdb notifications, and pointer for + // notification queue is created before we create switch startNotificationsProcessingThread(); SWSS_LOG_NOTICE("syncd listening for events"); diff --git a/syncd/syncd_notifications.cpp b/syncd/syncd_notifications.cpp index 1af5b05f0e4..2b53828a6f6 100644 --- a/syncd/syncd_notifications.cpp +++ b/syncd/syncd_notifications.cpp @@ -458,6 +458,7 @@ std::condition_variable cv; class ntf_queue_t { public: + ntf_queue_t() { } bool enqueue(swss::KeyOpFieldsValuesTuple msg); bool tryDequeue(swss::KeyOpFieldsValuesTuple& msg); size_t queueStats() @@ -480,7 +481,15 @@ class ntf_queue_t const size_t limit = 300000; }; -static std::unique_ptr ntf_queue_hdlr; + +/* + * Make sure that notification queue pointer is populated before we start + * thread, and before we create_switch, since at switch_create we can start + * receiving fdb_notifications which will arrive on different thread and + * will call queueStats() when queue pointer could be null (this=0x0). + */ + +static std::unique_ptr ntf_queue_hdlr = std::unique_ptr(new ntf_queue_t); bool ntf_queue_t::tryDequeue( _Out_ swss::KeyOpFieldsValuesTuple &item) @@ -641,8 +650,6 @@ void ntf_process_function() { SWSS_LOG_ENTER(); - ntf_queue_hdlr = std::unique_ptr(new ntf_queue_t); - while (runThread) { cv.wait(ulock);