Skip to content

Commit

Permalink
[syncd] Move logSet logGet under mutex to prevent race condition (#1505)
Browse files Browse the repository at this point in the history
* [syncd] Move logSet logGet under mutex to prevent race condition

Fixes: sonic-net/sonic-buildimage#21180

Mutex is added to protect m_logLevelMap when doing logSet from multiple thread

Co-authored-by: Jianquan Ye <[email protected]>
  • Loading branch information
kcudnik and yejianquan authored Feb 6, 2025
1 parent e11a959 commit b664f08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,7 @@ sai_status_t VendorSai::logSet(
_In_ sai_api_t api,
_In_ sai_log_level_t log_level)
{
MUTEX();
SWSS_LOG_ENTER();

m_logLevelMap[api] = log_level;
Expand All @@ -1967,6 +1968,7 @@ sai_status_t VendorSai::queryApiVersion(
sai_log_level_t VendorSai::logGet(
_In_ sai_api_t api)
{
MUTEX();
SWSS_LOG_ENTER();

auto it = m_logLevelMap.find(api);
Expand Down
11 changes: 11 additions & 0 deletions unittest/syncd/TestVendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,17 @@ TEST(VendorSai, bulk_meter_rules)
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.remove((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, meter_policy1));
}

TEST(VendorSai, logSet_logGet)
{
VendorSai sai;
sai.apiInitialize(0, &test_services);

EXPECT_EQ(SAI_STATUS_SUCCESS, sai.logSet(SAI_API_PORT, SAI_LOG_LEVEL_DEBUG));

EXPECT_EQ(SAI_LOG_LEVEL_DEBUG, sai.logGet(SAI_API_PORT));
EXPECT_EQ(SAI_LOG_LEVEL_NOTICE, sai.logGet(SAI_API_SWITCH));
}

TEST_F(VendorSaiTest, bulk_prefix_compression_entry)
{
sai_prefix_compression_entry_t *e = nullptr;
Expand Down

0 comments on commit b664f08

Please sign in to comment.