Skip to content

[BUG] CachePlugin crashes while writing responses for accepted rules with a null handle #7452

Closed

Description

@Aias00

Is there an existing issue for this?

  • I searched open and closed issues.

Current Behavior

A matched Cache rule with a null handle can enter the gateway rule cache, then turn a successful downstream response into a NullPointerException when the response body is written.

CachePluginDataHandler.handlerRule() skips a null ruleData.handle. CachePlugin.buildRuleHandle() then returns null from the rule-handle cache, but CacheHttpResponse.cacheResponse() unconditionally calls cacheRuleHandle.getTimeoutSeconds().

Expected Behavior

A rule accepted by the configuration/sync path should not crash successful responses. Either initialize documented default Cache settings or explicitly skip caching when no usable handle exists. If a handle is mandatory, reject that configuration consistently before publishing it.

Steps To Reproduce

  1. Enable the Cache plugin using the memory backend.
  2. Synchronize an enabled selector and a matching Cache rule with handle=null through the real CommonPluginDataSubscriber.
  3. Execute CachePlugin.execute() with a downstream chain that writes a plain-text response body.
  4. Observe an NPE at CachePlugin.java:146.

An offline harness executed the actual subscriber, handler, matching plugin and decorated response. The same setup with handle={"timeoutSeconds":60} completed successfully:

cachedHandle[valid]=CacheRuleHandle
validHandle=completed
cachedHandle[null]=null
nullHandle=java.lang.NullPointerException: Cannot invoke CacheRuleHandle.getTimeoutSeconds() because this.cacheRuleHandle is null

Reachability And Location

Impact

Severity: Medium. Confidence: high. Coverage: confirmed by an actual offline plugin execution.

Requests matching an accepted Cache rule without a handle fail during response processing instead of returning the otherwise successful downstream body. This requires absent/uncached rule settings; normal populated settings are the successful control case.

Suggested Fix And Regression Tests

Choose an explicit missing-handle policy: supply CacheRuleHandle.newInstance() defaults, skip caching, or reject invalid Cache rules at the configuration boundary. Verify missing, default and explicit timeout handles through real rule subscription plus CachePlugin.execute() and response writing.

Validation And Related Issues

Reviewed master at 67596c1d228b62da75cd0a0ecb47d0ac5d995384 (2.7.2-SNAPSHOT). Independent review and leader reproduction both confirmed the crash. Existing CachePluginTest: 5 tests passed, but lack this case.

#6877 covered similar absent-handle failures in Hystrix/Resilience4J/Sentinel/RateLimiter. #6772 covered stale handle removal in other handlers. #6505/#6506 cover Cache response restoration/key semantics. This report is the current Cache response-write null-handle path.

No live Admin/dashboard/gateway E2E environment was started. The DTO/service/schema acceptance path was inspected; the offline runtime harness starts at the gateway subscriber.

Activity

  1. added
    type: bug
    on Oct 7, 2026
  2. github-actions commented on Oct 7, 2026

    @github-actions
    Contributor

    👋 Hello @yuluo-yx

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

  3. Emryswu commented on Oct 11, 2026

    @Emryswu
    Contributor

    Hi, I'd like to work on this issue. I plan to skip caching when the cache rule handle is null. Could you assign it to me?

  4. Aias00 commented on Oct 11, 2026

    @Aias00
    ContributorAuthor

    Hi, I'd like to work on this issue. I plan to skip caching when the cache rule handle is null. Could you assign it to me?

    just comment /assign

  5. Emryswu commented on Oct 11, 2026

    @Emryswu
    Contributor

    C:/Program Files/Git/assign

  6. Emryswu commented on Oct 11, 2026

    @Emryswu
    Contributor

    /assign

  7. added a commit that references this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature: plugintype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions