From cbdc13de86c5b7787f29d7cbba6fe2c0b6756f5c Mon Sep 17 00:00:00 2001 From: Oleksandr Ivantsiv Date: Wed, 3 May 2017 19:44:42 +0300 Subject: [PATCH] [acl]: Fix crash in ACL counters thread. (#203) * Revert "[aclorch]: Temporarily disable ACL thread of collecting counters (#202)" This reverts commit 2f594c75036dfd41b6b40dd5b92f4fda7ebb7a68. * [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. --- orchagent/aclorch.cpp | 6 ++++++ orchagent/aclorch.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 7727fc02b5ba..4a07d2eee3ba 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -817,6 +817,10 @@ AclOrch::AclOrch(DBConnector *db, vector tableNames, PortsOrch *portOrch } m_mirrorOrch->attach(this); + + // Should be initialized last to guaranty that object is + // initialized before thread start. + m_countersThread = thread(AclOrch::collectCountersThread, this); } AclOrch::~AclOrch() @@ -825,6 +829,8 @@ AclOrch::~AclOrch() m_bCollectCounters = false; m_sleepGuard.notify_all(); + + m_countersThread.join(); } void AclOrch::update(SubjectType type, void *cntx) diff --git a/orchagent/aclorch.h b/orchagent/aclorch.h index 67d7735fad32..b826989fe01a 100644 --- a/orchagent/aclorch.h +++ b/orchagent/aclorch.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -274,6 +275,8 @@ class AclOrch : public Orch, public Observer PortsOrch *m_portOrch; MirrorOrch *m_mirrorOrch; + + thread m_countersThread; }; #endif /* SWSS_ACLORCH_H */