Multithreaded environment: RwLock needed around Enforcer with sqlx-adapter?
bk138 opened this issue · 6 comments
I've got a question about casbin-rs usage: I'm using it with actix-web and the example states that the Enforcer should be wrapped in an RwLock. I wonder if this is because of the example using FileAdapter and that the protection by the RwLock can maybe be omitted when using a DB adapter like sqlx-adapter? Or does the RwLock protect state inside the single Enforcer instance? Thanks!
@smrpn @hackerchai @PsiACE @GopherJ
I've got a question about casbin-rs usage: I'm using it with actix-web and the example states that the Enforcer should be wrapped in an RwLock. I wonder if this is because of the example using FileAdapter and that the protection by the RwLock can maybe be omitted when using a DB adapter like sqlx-adapter? Or does the RwLock protect state inside the single Enforcer instance? Thanks!
We use RwLock because actix-web is actually multi-threads when handling concurrent requests. In this way, you can use adapter to work with cash in.
We use RwLock because actix-web is actually multi-threads when handling concurrent requests. In this way, you can use adapter to work with cash in.
Yep, the question is more like: is Enforcer thread-safe (maybe only with certain adapters)? 529554e kinda hints at that. If it is not, it's maybe a good idea to state that in the docs. Would you accept a PR to the README adding a hint?
We use RwLock because actix-web is actually multi-threads when handling concurrent requests. In this way, you can use adapter to work with cash in.
Yep, the question is more like: is Enforcer thread-safe (maybe only with certain adapters)? 529554e kinda hints at that. If it is not, it's maybe a good idea to state that in the docs. Would you accept a PR to the README adding a hint?
The enforcer is not thread-safe. PR is always welcomed.
From my experience, sqlx adapter will update the DB, but not the enforcer's model, so that any changes will not have any effect.