apache / apache/shenyu

[BUG] AbstractLogCollector.initQueue() has thread-unsafe side effects on instance fields

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

Description

- severity: High
- files: `shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/collector/AbstractLogCollector.java:139-144`
- description: `initQueue()` is called from `collect()` via `bufferQueueS.computeIfAbsent(...)`. Inside, instance fields `bufferSize` and `bufferQueue` are reassigned as side effects. Neither field is `volatile`. Multiple request threads calling `collect()` concurrently with different `selectorId`s race on these reassignments; non-volatile `bufferSize` may be stale when read at line 94 (`bufferQueue.size() < bufferSize`).
- impact: Race on `bufferSize`/`bufferQueue` can cause incorrect capacity checks → premature log drops or `IllegalStateException`.
- suggested_fix: Make `initQueue` return a holder (queue + capacity) instead of mutating shared instance fields.
- confidence: High
- related_existing: none

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with AbstractLogCollector.java at collect() and initQueue() lines 139-144, then trace how bufferQueueS.computeIfAbsent handles each selectorId. Verify concurrent collection with different selectorIds no longer races on capacity or queue state, and that capacity checks do not cause premature drops or IllegalStateException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.