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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions enforcer_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

defer e.m.Unlock()
return e.Enforcer.SavePolicy()
}

Expand Down
0