Skip to content

Commit

Permalink
Fix data race in on_switch_shutdown_request() (#2931)
Browse files Browse the repository at this point in the history
The data race in on_switch_shutdown_request() is the following:

* the on_switch_shutdown_request() calls exit() which calls the destructors for global static variables (e.g.BufferOrch::m_buffer_type_maps) * in parallel to that, orchagent accesses the global static variables

A fix is to avoid calling the destructors by using quick_exit() instead of exit()
  • Loading branch information
Yakiv-Huryk authored Oct 13, 2023
1 parent b9313df commit 755b260
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion orchagent/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ extern "C" {
#include "logger.h"
#include "notifications.h"

#ifdef ASAN_ENABLED
#include <sanitizer/lsan_interface.h>
#endif

void on_fdb_event(uint32_t count, sai_fdb_event_notification_data_t *data)
{
// don't use this event handler, because it runs by libsairedis in a separate thread
Expand All @@ -30,5 +34,16 @@ void on_switch_shutdown_request(sai_object_id_t switch_id)
/* TODO: Later a better restart story will be told here */
SWSS_LOG_ERROR("Syncd stopped");

exit(EXIT_FAILURE);
/*
The quick_exit() is used instead of the exit() to avoid a following data race:
* the exit() calls the destructors for global static variables (e.g.BufferOrch::m_buffer_type_maps)
* in parallel to that, orchagent accesses the global static variables
Since quick_exit doesn't call atexit() flows, the LSAN check is called explicitly via __lsan_do_leak_check()
*/

#ifdef ASAN_ENABLED
__lsan_do_leak_check();
#endif

quick_exit(EXIT_FAILURE);
}

0 comments on commit 755b260

Please sign in to comment.