Skip to content

Commit 8585803

Browse files
authored
[sairedis] Unlock api mutex for communication mode (sonic-net#812)
This will remove possible deadlock when notification arrives during communication channel destructor thread join.
1 parent c69549a commit 8585803

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/inc/SaiInternal.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#pragma once
22

33
#define MUTEX() std::lock_guard<std::recursive_mutex> _lock(m_apimutex)
4+
#define MUTEX_UNLOCK() m_apimutex.unlock()

lib/src/Sai.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,25 @@ sai_status_t Sai::set(
196196

197197
if (RedisRemoteSaiInterface::isRedisAttribute(objectType, attr))
198198
{
199+
if (attr->id == SAI_REDIS_SWITCH_ATTR_REDIS_COMMUNICATION_MODE)
200+
{
201+
// Since communication mode destroys current channel and creates
202+
// new one, it may happen, that during this SET api execution when
203+
// api mutex is acquired, channel destructor will be blocking on
204+
// thread->join() and channel thread will start processing
205+
// incoming notification. That notification will be synchronized
206+
// with api mutex and will cause deadlock, so to mitigate this
207+
// scenario we will unlock api mutex here.
208+
//
209+
// This is not the perfect, but assuming that communication mode is
210+
// changed in single thread and before switch create then we should
211+
// not hit race condition.
212+
213+
SWSS_LOG_NOTICE("unlocking api mutex for communication mode");
214+
215+
MUTEX_UNLOCK();
216+
}
217+
199218
// skip metadata if attribute is redis extension attribute
200219

201220
// TODO this is setting on all contexts, but maybe we want one specific?

0 commit comments

Comments
 (0)