Skip to content

Commit

Permalink
[acl]: Fix crash in ACL counters thread. (sonic-net#203)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
oleksandrivantsiv authored and lguohan committed May 3, 2017
1 parent 2f594c7 commit cbdc13d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ AclOrch::AclOrch(DBConnector *db, vector<string> 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()
Expand All @@ -825,6 +829,8 @@ AclOrch::~AclOrch()

m_bCollectCounters = false;
m_sleepGuard.notify_all();

m_countersThread.join();
}

void AclOrch::update(SubjectType type, void *cntx)
Expand Down
3 changes: 3 additions & 0 deletions orchagent/aclorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <sstream>
#include <thread>
#include <mutex>
#include <tuple>
#include <condition_variable>
Expand Down Expand Up @@ -274,6 +275,8 @@ class AclOrch : public Orch, public Observer

PortsOrch *m_portOrch;
MirrorOrch *m_mirrorOrch;

thread m_countersThread;
};

#endif /* SWSS_ACLORCH_H */

0 comments on commit cbdc13d

Please sign in to comment.