Skip to content

[BUG] DividePlugin.beginTime is a shared mutable instance field, racy under shortestResponse load balancing #6544

Closed

Description

@Aias00

Description

private Long beginTime; is a plain instance field on the DividePlugin singleton bean. In the SHORTEST_RESPONSE branch it is set per-request (beginTime = System.currentTimeMillis()) and later read in successResponseTrigger (upstream.getSucceededElapsed().addAndGet(System.currentTimeMillis() - beginTime)). With concurrent requests, request B overwrites beginTime while request A is still in flight, so A's completion computes now - <B's start time> — a wrong (often negative or far too small) elapsed value that is added to the upstream's cumulative succeededElapsed counter.

Location

shenyu-plugin-divide/.../DividePlugin.java:63 (field), 137 (write), 197 (read in successResponseTrigger)

Impact

With two or more concurrent HTTP requests matching a divide rule whose loadBalance is shortestResponse, ShortestResponseLoadBalancer.doSelect picks upstreams by succeededAverageElapsed * inflight; corrupted averages produce wrong "shortest" selections — traffic is steered to the wrong upstream. The corruption is cumulative (addAndGet of bad deltas), so it persists and worsens.

Suggested fix

Do not store the start time on the singleton. Capture start as a local final long and use chain.execute(exchange).doOnSuccess(e -> successResponseTrigger(upstream, start)), or stash it in an exchange attribute.

Related existing issue(s)

#6427 (closed) was about P2C EWMA decay order reversal; this is a different latency-bookkeeping race in DividePlugin itself, distinct.

Identified during the 2026-08-02 audit; full list in docs/issue-candidates-2026-08-02.md.

Activity

  1. added
    type: bug
    priority: high
    on Aug 2, 2026
  2. github-actions commented on Aug 2, 2026

    @github-actions
    Contributor

    👋 Hello @yuluo-yx

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

  3. Aias00 commented on Oct 1, 2026

    @Aias00
    ContributorAuthor

    Closing as fixed by #6429. DividePlugin no longer stores beginTime as shared mutable instance state; shortest-response timing now uses a per-request local value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: dividepriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions