Skip to content

Commit cbdc13d

Browse files
oleksandrivantsivlguohan
authored andcommitted
[acl]: Fix crash in ACL counters thread. (sonic-net#203)
* Revert "[aclorch]: Temporarily disable ACL thread of collecting counters (sonic-net#202)" This reverts commit 2f594c7. * [acl]: Fix crash in ACL counters thread. Due to incorrect usage of thread class and race conditions from time to time conter thread was accessing AclOrch object members before thay were initialized.
1 parent 2f594c7 commit cbdc13d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

orchagent/aclorch.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ AclOrch::AclOrch(DBConnector *db, vector<string> tableNames, PortsOrch *portOrch
817817
}
818818

819819
m_mirrorOrch->attach(this);
820+
821+
// Should be initialized last to guaranty that object is
822+
// initialized before thread start.
823+
m_countersThread = thread(AclOrch::collectCountersThread, this);
820824
}
821825

822826
AclOrch::~AclOrch()
@@ -825,6 +829,8 @@ AclOrch::~AclOrch()
825829

826830
m_bCollectCounters = false;
827831
m_sleepGuard.notify_all();
832+
833+
m_countersThread.join();
828834
}
829835

830836
void AclOrch::update(SubjectType type, void *cntx)

orchagent/aclorch.h

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <iostream>
55
#include <sstream>
6+
#include <thread>
67
#include <mutex>
78
#include <tuple>
89
#include <condition_variable>
@@ -274,6 +275,8 @@ class AclOrch : public Orch, public Observer
274275

275276
PortsOrch *m_portOrch;
276277
MirrorOrch *m_mirrorOrch;
278+
279+
thread m_countersThread;
277280
};
278281

279282
#endif /* SWSS_ACLORCH_H */

0 commit comments

Comments
 (0)