Skip to content

fix(consumer): missed consumer update due to wrong version in cache#12413

Merged
Revolyssup merged 20 commits into
apache:masterfrom
Revolyssup:revolyssup/add-fix-consumer-1
Jul 11, 2025
Merged

fix(consumer): missed consumer update due to wrong version in cache#12413
Revolyssup merged 20 commits into
apache:masterfrom
Revolyssup:revolyssup/add-fix-consumer-1

Conversation

@Revolyssup

@Revolyssup Revolyssup commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Description

Fixes #12393
This PR introduced a critical bug #11840 due to which consumers are not updated until a subsequent update in credentials due to credential version being used even for checking consumer update.

More context on this comment: https://github.com/apache/apisix/pull/11840/files#r2193898420

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 9, 2025
Comment thread apisix/consumer.lua Outdated
Comment thread apisix/consumer.lua Outdated
Comment thread t/admin/consumer-credentials.t Outdated
Comment thread apisix/consumer.lua Outdated
nic-6443
nic-6443 previously approved these changes Jul 9, 2025
@Baoyuantop

Copy link
Copy Markdown
Contributor

Will this pr fixed #12393?

@Revolyssup

Copy link
Copy Markdown
Contributor Author

Will this pr fixed #12393?

Yes

nic-6443
nic-6443 previously approved these changes Jul 9, 2025
nic-6443
nic-6443 previously approved these changes Jul 9, 2025
nic-6443
nic-6443 previously approved these changes Jul 9, 2025
@bzp2010

bzp2010 commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Truth be told, I didn't understand your modifications. Can you provide more insight? 🤔

@Revolyssup

Revolyssup commented Jul 9, 2025

Copy link
Copy Markdown
Contributor Author

As this comment explains https://github.com/apache/apisix/pull/11840/files#r2193898420
The version being used in the cache was that of credential.modified index. This means until the credential is modified, we will use stale value from cache.
But in the scenario, where the underlying consumer has been modified, we need to recalculate and not use the old value. Therefore in my changes, I have used credential.modified..consumer.modified as the version, so that even when underlying consumer changes, a resync is triggered.

My changes are a revert of the bug introducing PR + only adding expensive operation (.clone()) in the lrucache callback.

@bzp2010

bzp2010 commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Thanks for the explanation, I seem to have run into some GitHub bug that prevents the web page from pinpointing the exact comment you pointed out.
Anyway, I've seen it. I will check the code again.

Comment thread apisix/consumer.lua Outdated
-- if the val is a Consumer, clone it to the local consumer;
-- if the val is a Credential, to get the Consumer by consumer_name and then clone
-- it to the local consumer.
local consumer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't prefer current code style, it not easy to read

We can put those changing code to one or two seperate functions, and check the return value if it failed

Reducing the nesting depth can make the code more readable.

@Revolyssup
Revolyssup merged commit 2b774e5 into apache:master Jul 11, 2025
22 of 25 checks passed
@Revolyssup
Revolyssup deleted the revolyssup/add-fix-consumer-1 branch July 11, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Consumer plugins and labels not updated on authenticated requests when using credentials

5 participants