Skip to content

[Bug]The Redis Watcherex may fail to update the rules in an instance due to errors caused by database unique constraints when notifying different instances to update rules. #1581

@whxxxxxxxxxx

Description

@whxxxxxxxxxx

When we update rules with the action of the notification and the watcher Redis WatcherEX,the message will be accepted by all instance,but if we set the unique index in our database,all update action will failed because of the code bellow:

	if e.dispatcher != nil && e.autoNotifyDispatcher {
		return true, e.dispatcher.AddPolicies(sec, ptype, [][]string{rule})
	}

	if e.model.HasPolicy(sec, ptype, rule) {
		return false, nil
	}

	if e.shouldPersist() {
		if err := e.adapter.AddPolicy(sec, ptype, rule); err != nil {
			if err.Error() != notImplemented {
				return false, err
			}
		}
	}

	e.model.AddPolicy(sec, ptype, rule)

	if sec == "g" {
		err := e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{rule})
		if err != nil {
			return true, err
		}
	}

	return true, nil

The function addPolicyWithoutNotify will check if the instance should persist rule to database,and the function will fail because of the unique index,and the function will return,the important action e.model.AddPolicy(sec, ptype, rule) will be skipped , so the rule will not be add to this instance.

I have tried to rewrite the default callback function in Redis WatcherEX,but I can visit the private variable in package casbin.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions