apache / apache/shenyu

[BUG] UpstreamCheckService.fetchUpstreamData stores a LinkedList in UPSTREAM_MAP, but submitJust assumes CopyOnWriteArrayList (CME risk)

Open Beginner friendly
#6,704 1 comment 0 reactions 0 assignees View on GitHub
admin priority: medium type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: Medium
- files: `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java:468-496` vs `:213-235`
- description: `fetchUpstreamData` creates `List commonUpstreams = new LinkedList<>()` and `UPSTREAM_MAP.put(selectorDO.getId(), commonUpstreams)`. Later, `submitJust` does `MapUtils.computeIfAbsent(UPSTREAM_MAP, selectorId, k -> new CopyOnWriteArrayList<>())` — since the key already exists, it returns the **LinkedList**, then mutates it with `add`/`removeIf`. Meanwhile the scheduled `check` thread iterates the same list. LinkedList is not thread-safe and its iterator is fail-fast → CME.
- impact: Registration/check races can throw CME inside the scheduler (silently swallowed) or lose upstream entries.
- suggested_fix: Always store `CopyOnWriteArrayList` in `UPSTREAM_MAP`; have `fetchUpstreamData` build a `CopyOnWriteArrayList`.
- confidence: Medium
- related_existing: none.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java, comparing fetchUpstreamData at lines 468-496 with submitJust at lines 213-235 and the scheduled check path. Verify that UPSTREAM_MAP consistently contains CopyOnWriteArrayList instances and that concurrent registration and checking no longer risks a ConcurrentModificationException or lost upstream entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.