Skip to content

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

Merged
tokers merged 4 commits into
apache:masterfrom
nic-chen:fix-global-rule
Feb 18, 2021
Merged

fix: should assign value to api_ctx.global_rules before running global rules#3595
tokers merged 4 commits into
apache:masterfrom
nic-chen:fix-global-rule

Conversation

@nic-chen

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

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Is this a bug? Which PR introduced it?

Comment thread apisix/init.lua Outdated

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

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.

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Is this a bug? Which PR introduced it?

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

@nic-chen

Copy link
Copy Markdown
Member Author

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

@tokers

tokers commented Feb 18, 2021

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
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

tokers commented Feb 18, 2021

Copy link
Copy Markdown
Contributor

@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.

Comment thread apisix/plugin.lua
Comment thread apisix/plugin.lua
@@ -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
Copy Markdown
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
Copy Markdown
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