Skip to content

Enforcer hangs during multi-threaded modifications #336

Closed
@v-loboda

Description

@v-loboda

Hi guys

We encountered a problem in an environment where intensive policy modification occurs. It's very difficult to reproduce, and I can't do it reliably.
We have rbac model, several nodes with synchronization via IWatcher and a lot of policy changes including removing them.

Sometimes, very rarely, we catch an error
Error Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock.

From my point of view, there are 3 problem pleces:

  1. DefaultPolicyStore.Node class, where PolicyTextSet collection can be changed from different threads in several places
  2. Casbin.Rbac.Role class where _roles collection can be changed from different threads
  3. InternalEnforce class and the InternalEnforce method, where Scanner.Interrupt is not executed on every execution path. This can lead to a deadlock in the internal Iterator->node.Lock, where after _node.Lock.EnterReadLock ExitReadLock will not be executed.

Metadata

Metadata

Labels

bugSomething isn't workingreleased

Type

No type

Projects

Status

Casbin.NET Easy Tasks

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions