8000 fix: wrong type of locking by JalinWang · Pull Request #1061 · casbin/casbin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: wrong type of locking #1061

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

Merged
merged 1 commit into from
Jul 27, 2022
Merged

Conversation

JalinWang
Copy link
Member

SavePolicy() should require the lock for RW.

@casbin-bot
Copy link
Member

@tangyang9464 please review

@casbin-bot casbin-bot requested a review from tangyang9464 July 26, 2022 13:29
@hsluoyz
Copy link
Member
hsluoyz commented Jul 26, 2022

@tangyang9464

@@ -131,8 +131,8 @@ func (e *SyncedEnforcer) LoadIncrementalFilteredPolicy(filter interface{}) error

// SavePolicy saves the current policy (usually after changed with Casbin API) back to file/database.
func (e *SyncedEnforcer) SavePolicy() error {
e.m.RLock()
defer e.m.RUnlock()
e.m.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be a race in SavePolicy, I think it just reads the resource

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving policies cause the adapter to write to, i.e., a database.
A RemovePolicy() and the SavePolicy will emit concurrent database writes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adapter itself should ensure transaction security, but it seems that it does not now, it can only be locked here

Copy link
Member
@tangyang9464 tangyang9464 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hsluoyz hsluoyz merged commit 2f8b4fc into casbin:master Jul 27, 2022
@github-actions
Copy link

🎉 This PR is included in version 2.51.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@JalinWang JalinWang deleted the wrong_lock_type branch August 18, 2022 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0