Skip to content

Commit

Permalink
Assert that holders are added to sessions only with the Matter lock h…
Browse files Browse the repository at this point in the history
…eld.

Adding/removing holders manipulates circular lists, and if we end up with data
races on these manipulations we can end up in bad states.  Since sessions are
somewhat singleton resources, and the "hold on to a session" operation is pretty
hidden in many cases, it's easy to end up with a situation where a session is
being pointed to by objects being manipulated on multiple threads and hard to
catch this via manual code inspection.
  • Loading branch information
bzbarsky-apple committed Jun 30, 2022
1 parent 31ddf98 commit 04728aa
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/transport/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <lib/core/PeerId.h>
#include <lib/core/ScopedNodeId.h>
#include <messaging/ReliableMessageProtocolConfig.h>
#include <platform/LockTracker.h>
#include <transport/SessionHolder.h>
#include <transport/raw/PeerAddress.h>

Expand Down Expand Up @@ -55,12 +56,14 @@ class Session

void AddHolder(SessionHolder & holder)
{
assertChipStackLockedByCurrentThread();
VerifyOrDie(!holder.IsInList());
mHolders.PushBack(&holder);
}

void RemoveHolder(SessionHolder & holder)
{
assertChipStackLockedByCurrentThread();
VerifyOrDie(mHolders.Contains(&holder));
mHolders.Remove(&holder);
}
Expand Down

0 comments on commit 04728aa

Please sign in to comment.