Closed herkit closed 1 year ago
@sagilio @sociometry @AsakusaRinne
Thank you for telling us this issue. I agree with you that it's caused by not using concurrent dictionary in GFunctionCache
. We also noticed it two weeks ago and fixed it in #297 . However, this fix is not included in 2.0.0.-preview.4
. If you don't mind using an unstable release, I think it can be fixed with the version 2.0.0-preview.4-build.332.preview.a6c464e
by specifying the following config file as nuget source. We'll publish a stable release in the future. :)
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="casbin-net.myget.org" value="https://www.myget.org/F/casbin-net/api/v3/index.json" />
</packageSources>
</configuration>
@AsakusaRinne Thank you, I will try this, however it seems SyncedEnforcer is left out of this package, is the default Enforcer thread safe?
Yes, there are some break changes in this package, including making DefaultEnforcer
thread safe.
We've created a rbac as a service api that registers the enforcer and model as a singleton in our DI container. The policy model is populated incrementally by a worker service that is triggering on changes in our backend database, we're not using an Adapter or a Watcher to populate model. Our issue seems to occur intermittently. We'll suddenly start getting InvalidOperationExceptions on Enforce.
We've seen a lot of InvalidOperationExceptions on enforce lately. After upgrading from 1.4. to 1.12. it became extremely frequent, then we upgraded to 2.0.0.-preview.4 and it seemed ok, but now it has started failing again.
Our policy definition:
Code that updates our model (abbreviated):
This is our stack trace (from Enfore() and onward):
I suspect that the issue is with the current IGFunctionCache implemetation not using a ConcurrentDictionary.
I suggest either using a ConcurrentDictionary by default or giving us the option to replace the IGFunctionCachePool and IGFunctionCache with a custom implementations that does this.