Skip to content
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

fix: should assign value to api_ctx.global_rules before running global rules #3595

Merged
merged 4 commits into from
Feb 18, 2021

Conversation

nic-chen
Copy link
Member

@nic-chen nic-chen commented Feb 15, 2021

What this PR does / why we need it:

this bug introduced by #3396.

should assign value to api_ctx.global_rules before running global rules, otherwise if a plugin exits in the access phase, global rules will not be able to run in the subsequent phases.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@moonming
Copy link
Member

Is this a bug? Which PR introduced it?

apisix/init.lua Outdated
@@ -297,8 +297,8 @@ function _M.http_access_phase()
router.router_http.match(api_ctx)

-- run global rule
plugin.run_global_rules(api_ctx, router.global_rules, "access")
api_ctx.global_rules = router.global_rules
Copy link
Member

Choose a reason for hiding this comment

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

Do it in run_global_rules?
Need to update the api_router.lua too

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander
Thanks for reviewing.
I still have some doubts. The original code also assign value to api_ctx.global_rules after run_plugin, but it does not cause a bug like this. .

Copy link
Member Author

Choose a reason for hiding this comment

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

@spacewander
Thanks for reviewing.
I still have some doubts. The original code also assign value to api_ctx.global_rules after run_plugin, but it does not cause a bug like this. .

I re-checked the original code, it filtered plugins of global rule and assigned them to api_ctx.plugins, that is why..

@nic-chen
Copy link
Member Author

Is this a bug? Which PR introduced it?

yes, it's a bug. it's introduced by #3396

@nic-chen
Copy link
Member Author

@membphis @tokers @moonming please have a look when you have time, thanks.

@tokers
Copy link
Contributor

tokers commented Feb 18, 2021

@nic-chen Could you tell me where we use api_ctx.global_rules? I saw the assignment but not found the usage.

@nic-chen
Copy link
Member Author

@nic-chen Could you tell me where we use api_ctx.global_rules? I saw the assignment but not found the usage.

use in:
https://github.com/apache/apisix/blob/master/apisix/init.lua#L481

and define in:
https://github.com/apache/apisix/blob/master/apisix/plugin.lua#L685-L714

you could also have a look at the prev PR #3396 for more detail.

@nic-chen
Copy link
Member Author

yes, it's a bug. it's introduced by #3396

Actually #3396 is not the real cause of the bug, but it exposes the bug

@tokers
Copy link
Contributor

tokers commented Feb 18, 2021

@nic-chen Could you tell me where we use api_ctx.global_rules? I saw the assignment but not found the usage.

use in:
https://github.com/apache/apisix/blob/master/apisix/init.lua#L481

and define in:
https://github.com/apache/apisix/blob/master/apisix/plugin.lua#L685-L714

you could also have a look at the prev PR #3396 for more detail.

Got it.

@@ -689,6 +689,10 @@ function _M.run_global_rules(api_ctx, global_rules, phase_name)
local orig_conf_version = api_ctx.conf_version
Copy link
Member

Choose a reason for hiding this comment

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

better style, we can fix it in a new PR

function _M.run_global_rules(api_ctx, global_rules, phase_name)
    if not global_rules or not global_rules.values
       and #global_rules.values == 0 then
        return
    end

    -- your code
end

Copy link
Member Author

Choose a reason for hiding this comment

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

better style, we can fix it in a new PR

function _M.run_global_rules(api_ctx, global_rules, phase_name)
    if not global_rules or not global_rules.values
       and #global_rules.values == 0 then
        return
    end

    -- your code
end

OK

@tokers tokers merged commit 82018b9 into apache:master Feb 18, 2021
@nic-chen nic-chen deleted the fix-global-rule branch February 18, 2021 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants