Skip to content

Fixes #6882:Prevent cross-request context leakage in mock expressions - #7049

Open
BobSong-dev wants to merge 6 commits into
apache:masterfrom
BobSong-dev:fix/6882-mock-concurrent-context
Open

BobSong-dev wants to merge 6 commits into
apache:masterfrom
BobSong-dev:fix/6882-mock-concurrent-context

Conversation

@BobSong-dev

@BobSong-dev BobSong-dev commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #6882

Background

Both mock expression generators stored the request variable in a shared static EvaluationContext. During concurrent evaluations, one request could overwrite req before another evaluation read it, causing cross-request data leakage and incorrect mock responses.

Changes

  • Create an independent EvaluationContext for each expression evaluation;
  • Apply the per-evaluation context to both ExpressionGenerator and StandardExpressionGenerator;
  • Add concurrent regression coverage for request-specific JSON values while retaining the existing single-request expression coverage.

Verification

Local:

  • mvn.cmd -o -nsu -pl shenyu-plugin/shenyu-plugin-mock -am -Dtest=ExpressionGeneratorTest -DfailIfNoTests=false -Djacoco.skip=true test: Tests run: 15, Failures: 0, Errors: 0, Skipped: 0; BUILD SUCCESS.
  • Checkstyle: 0 violations.
  • git diff --check: passed.

@BobSong-dev BobSong-dev changed the title Fixes #6882: Isolate request context during mock expression evaluation Fixes #6882: Isolate request context during mock expression evaluation - #7049 Sep 9, 2026
@BobSong-dev BobSong-dev changed the title Fixes #6882: Isolate request context during mock expression evaluation - #7049 Prevent cross-request context leakage in mock expressions Sep 9, 2026
@BobSong-dev BobSong-dev changed the title Prevent cross-request context leakage in mock expressions Fixes #6882:Prevent cross-request context leakage in mock expressions Sep 9, 2026
…rrent-context

# Conflicts:
#	shenyu-plugin/shenyu-plugin-mock/src/main/java/org/apache/shenyu/plugin/mock/generator/ExpressionGenerator.java
#	shenyu-plugin/shenyu-plugin-mock/src/main/java/org/apache/shenyu/plugin/mock/generator/StandardExpressionGenerator.java

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds concurrent regression coverage to prevent cross-request leakage in mock expression evaluation.

Changes:

  • Tests concurrent request-specific values for both expression generators.
  • Reuses a two-thread executor and synchronizes evaluations with a barrier.
File summaries
File Description
shenyu-plugin/shenyu-plugin-mock/src/test/java/org/apache/shenyu/plugin/mock/generator/ExpressionGeneratorTest.java Updated as part of this pull request.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

for (int i = 0; i < 100; i++) {
MockRequest firstRequest = createRequest("first");
MockRequest secondRequest = createRequest("second");
CyclicBarrier barrier = new CyclicBarrier(2);
@Aias00

Aias00 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Heads-up (PMC Aias00): your PR's CI failures are in shared infrastructure checks (k8s-examples-http, e2e-case-logging-rocketmq, build-docker-images) that are currently failing across many unrelated PRs. This looks like a CI-environment issue, not a problem with your change. Please re-run the failed checks; the code change itself appears fine. No code changes needed for these specific failures.

@BobSong-dev

Copy link
Copy Markdown
Contributor Author

Heads-up (PMC Aias00): your PR's CI failures are in shared infrastructure checks (k8s-examples-http, e2e-case-logging-rocketmq, build-docker-images) that are currently failing across many unrelated PRs. This looks like a CI-environment issue, not a problem with your change. Please re-run the failed checks; the code change itself appears fine. No code changes needed for these specific failures.单挑对决(PMC Aias00):你们的测试环境中的 CI 测试失败,问题出在共享基础设施的检查上( k8s-examples-httpe2e-case-logging-rocketmqbuild-docker-images ),这些检查在许多无关的 PR 中都会出现失败情况。这看起来像是 CI 环境的问题,而不是代码本身的问题。请重新执行那些失败的检查;代码本身似乎没有什么问题。对于这些特定的失败情况,不需要对代码进行任何修改。

Thanks for your review,I will deal with it

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved as PMC (Aias00). Reviewed the diff — small, well-scoped fix with regression tests; mergeable.

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.

[BUG] MockPlugin NPE when httpStatusCode is null in MockHandle (unboxing null Integer to HttpStatus.valueOf)

3 participants