Skip to content

fix: use thread-safe upstream lists in UpstreamCheckService (#6704) - #7053

Open
juicewcode wants to merge 5 commits into
apache:masterfrom
juicewcode:fix/6704-upstream-map-thread-safe-list
Open

juicewcode wants to merge 5 commits into
apache:masterfrom
juicewcode:fix/6704-upstream-map-thread-safe-list

Conversation

@juicewcode

Copy link
Copy Markdown
Contributor

Fixes #6704

Summary

  • Build upstream lists in UpstreamCheckService#fetchUpstreamData with CopyOnWriteArrayList instead of LinkedList.
  • Prevent concurrent registration updates and scheduled health-check iteration from causing
    ConcurrentModificationException.

Test

  • Updated UpstreamCheckServiceTest#testFetchUpstreamData to verify the loaded upstream lists are CopyOnWriteArrayList
    instances.
  • Kept the existing assertions for selector entries and upstream counts.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

juicewcode and others added 4 commits September 10, 2026 22:17
…6704)

  Build upstream data with CopyOnWriteArrayList so submit and scheduled
  health checks can safely modify and iterate the same selector entries.
  Ensure replacement and health-check result lists stored in UPSTREAM_MAP
  use the same thread-safe implementation, and add regression assertions
  for lists loaded by fetchUpstreamData.
  Reuse existing CopyOnWriteArrayList instances when updating UPSTREAM_MAP
  and only copy lists that are not thread-safe. This preserves the shared
  list reference used by asynchronous submit tasks while ensuring ordinary
  lists are converted before being stored.

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

Health-check completion can still overwrite concurrent upstream updates, and the race is not covered by an active regression test.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates upstream list storage to avoid ConcurrentModificationException during concurrent health checks and registrations.

Changes:

  • Uses CopyOnWriteArrayList for fetched, replaced, and refreshed upstream lists.
  • Adds assertions verifying fetched lists use the thread-safe implementation.
File summaries
File Description
UpstreamCheckService.java Normalizes shared upstream lists to CopyOnWriteArrayList.
UpstreamCheckServiceTest.java Verifies fetched lists use CopyOnWriteArrayList.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

removePendingSync(successList);
if (!successList.isEmpty()) {
UPSTREAM_MAP.put(selectorId, successList);
UPSTREAM_MAP.put(selectorId, toThreadSafeList(successList));
upstreamCheckService.fetchUpstreamData();
assertTrue(upstreamMap.containsKey(MOCK_SELECTOR_NAME));
assertEquals(2, upstreamMap.get(MOCK_SELECTOR_NAME).size());
assertTrue(upstreamMap.get(MOCK_SELECTOR_NAME) instanceof CopyOnWriteArrayList);
@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.

@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. Note: the only failing CI checks (shenyu-integrated-test-*/e2e-case-logging-rocketmq) are failing cluster-wide across unrelated PRs (shared CI-env issue), not caused by this change.

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] UpstreamCheckService.fetchUpstreamData stores a LinkedList in UPSTREAM_MAP, but submitJust assumes CopyOnWriteArrayList (CME risk)

4 participants