Skip to content

fix(workflow): skip the action plugin in the chain to avoid double execution#13617

Merged
shreemaan-abhishek merged 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/workflow-plugin-double-exec
Jun 30, 2026
Merged

fix(workflow): skip the action plugin in the chain to avoid double execution#13617
shreemaan-abhishek merged 2 commits into
apache:masterfrom
shreemaan-abhishek:fix/workflow-plugin-double-exec

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

The workflow Plugin (priority 1006) can run a plugin such as limit-count (priority 1002) or limit-conn (priority 1003) as an action. When the same plugin is also configured directly in the normal plugin chain on the same Route/Service/Consumer/Global Rule, the plugin ends up running twice per request:

  1. once via the workflow action handler, and
  2. once in the normal chain (the workflow access handler returns nil on the non-rejected path, so it does not short-circuit the chain).

The visible impact is that a request is counted/limited twice. For limit-count the quota is consumed at 2x; the same applies to limit-conn (which is also double-counted in both access and log). This is reachable with stock plugins and a non-exotic configuration.

This PR adds plugin.skip_plugin(ctx, name) to mark the action plugin as skipped for the rest of the request, so once workflow runs it as an action it is not executed again in the normal chain. The skip is honored in both run_plugin loops (access/rewrite and log/header_filter/body_filter), so limit-conn's log-phase decrement is also handled only by the workflow action.

Which issue(s) this PR fixes:

N/A

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

…ecution

When a plugin such as limit-count or limit-conn runs as a workflow action
and the same plugin is also configured in the normal plugin chain, the plugin
runs twice per request (e.g. a request is counted twice against a rate limit).

Mark the action plugin as skipped for the rest of the request so it does not
run again in the chain.

Signed-off-by: shreemaan-abhishek <shreemaan.abhishek@gmail.com>
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a real double-execution problem when workflow runs a plugin as an action and the same plugin is also present in the normal plugin chain, by introducing a per-request “skip this plugin” mechanism to prevent the second execution.

Changes:

  • Add plugin.skip_plugin(ctx, name) and honor the skip list inside plugin.run_plugin loops to prevent double execution.
  • Update workflow plugin to mark the action plugin as skipped for the remainder of the request.
  • Add regression coverage to ensure limit-count is only applied once when used both in the chain and as a workflow action, and document the behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
t/plugin/workflow-without-case.t Adds a test scenario proving the action plugin is skipped in the normal chain to avoid double counting.
docs/en/latest/plugins/workflow.md Documents that action plugins are skipped in the normal chain for that request to prevent double execution.
apisix/plugins/workflow.lua Calls plugin.skip_plugin(ctx, action[1]) before executing the action handler.
apisix/plugin.lua Introduces skip_plugin and checks _skip_plugins during plugin execution loops.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/plugin.lua Outdated
Comment thread apisix/plugin.lua Outdated
Move the _skip_plugins check above run_meta_pre_function and the _plugin_name
assignment so a plugin run as a workflow action does not fire its meta
pre_function again, does not set plugin_run, and leaves no stale _plugin_name.

Signed-off-by: shreemaan-abhishek <shreemaan.abhishek@gmail.com>
@shreemaan-abhishek shreemaan-abhishek merged commit 9f694b2 into apache:master Jun 30, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants