Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ArgumentOutOfRangeException during high read/write scenarios #346

Closed
seanamorosoamtote opened this issue Apr 2, 2024 · 4 comments · Fixed by #362
Closed

System.ArgumentOutOfRangeException during high read/write scenarios #346

seanamorosoamtote opened this issue Apr 2, 2024 · 4 comments · Fixed by #362
Assignees
Labels
bug Something isn't working released

Comments

@seanamorosoamtote
Copy link
Contributor

During our testing phase we are continually updating the policies and testing enforcement of various domain objects. We noticed that very intermittently we will get an ArgumentOfRangeException with the following call stack:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at Casbin.Model.DefaultPolicyStore.Iterator.GetNext(IPolicyValues& values)
   at Casbin.Enforcer.InternalEnforce[TRequest,TPolicy](EnforceContext& context, TRequest& requestValues)
   at Casbin.Enforcer.InternalEnforce[TRequest](EnforceContext& context, TRequest& requestValues)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Casbin.Enforcer.EnforceAsync[TRequest](EnforceContext context, TRequest requestValues)

For now we are going to just try to retry the exception, but looking for a more stable solution here, thanks!

@casbin-bot
Copy link
Member

@casbin-bot casbin-bot added the question Further information is requested label Apr 2, 2024
@hsluoyz
Copy link
Member

hsluoyz commented Apr 4, 2024

@seanamorosoamtote can you provide the reproduce steps? Casbin model? policy? and code?

@seanamorosoamtote
Copy link
Contributor Author

Our model:

[request_definition] 
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, act

[role_definition]
g = _, _
g2 = _, _
g3 = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && (g2(r.dom, p.dom) || r.obj == p.dom) && g3(r.act, p.act)

The code that throws the exception is simply calling EnforceAsync(subject, domain, obj, action); on the IEnforcer.

It is very intermittent but occurs during our integration test phase where we are constantly reading and writing the policy. So there isn't a straight-forward reproducible steps, you would have to potentially create something that was updating the policy in the background while enforcing in another thread.

@sagilio sagilio added bug Something isn't working and removed question Further information is requested labels Jun 2, 2024
Copy link

🎉 This issue has been resolved in version 2.9.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
Development

Successfully merging a pull request may close this issue.

4 participants