LuckPerms

LuckPerms

41.4k Downloads

Setting same permission across servers with different server contexts replacing existing data

bloodmc opened this issue ยท 3 comments

commented

LP 5.1.63
GD 1.4.6

Shared storage - symlink json storage (user reported same issue with DB)

Issue - Setting permission via API with different server context affects other servers when using shared storage.

Steps I used to reproduce with GD

  1. Configure servers

Server1

  • set servername to server1 in LP config
  • set storage type to json in LP config
  • configure symlink of json-storage in luckperms folder

Server2

  • set servername to server2 in LP config
  • set storage type to json in LP config
  • configure symlink of json-storage in luckperms folder
  1. Launch both servers

  2. On server 1, run command /cf block-break stone false

  3. On server 2, run command /cf block-break stone true

Relevant code used for /cf command found here

https://github.com/bloodmc/GriefDefender/blob/master/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java#L704-L740

When the following line is executed in step 4
https://github.com/bloodmc/GriefDefender/blob/master/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java#L720

LP returns result FAIL_ALREADY_HAS

However, checking the default.json group shows

    {
      "permission": "griefdefender.flag.block-break",
      "value": false,
      "context": {
        "gd_claim": "4ae21d18-9fa8-49f9-9a63-e92301b96a30",
        "server": "server1",
        "target": "minecraft:stone"
      }
    },

If I change the value from TRUE to FALSE, it sets it and replaces the original permission. It ends up looking like this

    {
      "permission": "griefdefender.flag.block-break",
      "value": false,
      "context": {
        "gd_claim": "44704fc3-6637-4c54-8d87-ccc639dd01a7",
        "server": "server2",
        "target": "minecraft:stone"
      }
    },

Now here comes the strange part....
If I replace steps 3 and 4 with LP commands such as

/lp group default permission set griefdefender.block-break true gd_claim=XXXX server=server2 target=minecraft:stone

This seems to always work properly but when adding the node via API it has the issue described above.

Let me know if there is any additional information you need.

Update 1 - Downgraded second server to LP 5.1.16 just to see if this bug was related to the context satisfy changes and the problem persisted. It seems to be related to caching. If I restart the server before making a change, it seems to always work.

Update 2 - I confirmed that if I restart server before making a change, the permission is added properly.

Thanks!

commented

Symlinking isn't really a supported mechanism for syncing permissions between servers - the issue you're running into is that it takes some time for the changes to be detected by the other server.

If you always want to act on the most up-to-date representation of what's "in the file" - you need to call UserManager.loadUser, GroupManager.loadGroup before modifying - not just relying on what's cached in memory.

I don't think this is a bug as such - changing the API usage in GD as described above should resolve the issue. :)

commented

OK I reproduced the same issue with MySQL setup.

Setting permission on server 1 results in this row in luckperms_group_permissions

'6', 'default', 'griefdefender.flag.block-break', '0', 'server1', 'global', '0', '{\"gd_claim\":\"44704fc3-6637-4c54-8d87-ccc639dd01a7\",\"target\":\"minecraft:stone\"}'

Switching to server 2 and setting the same permission results in this row being replaced with

'7', 'default', 'griefdefender.flag.block-break', '1', 'server2', 'global', '0', '{\"gd_claim\":\"4ae21d18-9fa8-49f9-9a63-e92301b96a30\",\"target\":\"minecraft:stone\"}'

So is the only way to fix this issue to call loadUser and loadGroup? Is there any reason LP cannot confirm that the server context is the same before replacing the entire row?

Update 1 - Not sure if this matters but after every change, I'm calling saveUser or saveGroup. Could this be causing the issue? or should I wait until LP automatically saves changes?
Relevant code here
https://github.com/bloodmc/GriefDefender/blob/master/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java#L733
https://github.com/bloodmc/GriefDefender/blob/master/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java#L807-L818

Thanks

commented

As per our discussion, to fix this I have to call loadUser or loadGroup before making any changes.

Thanks!