JakeChampion / JakeChampion/trafficserver
[audit][cache] create_volume: self-declared 'really bad code' with a function-local static that breaks reinitialization
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 0
- Forks
- 0
- Avg merge
- 8h 2m
- Merged PRs (30d)
- 21
Description
Severity: medium · Category: logic-bug
Location: src/iocore/cache/CacheProcessor.cc:1335
What's wrong
create_volume() opens with the maintainer note 'This is some really bad code, and needs to be rewritten!' and immediately uses 'static int curr_vol = 0' flagged '// FIXME: this will not reinitialize correctly'. Because the round-robin cursor persists across invocations/reconfigurations, volume placement after a cache volume reconfiguration depends on stale state from the previous configuration pass - a latent correctness bug in cache stripe assignment, in addition to being non-reentrant.
Evidence
// This is some really bad code, and needs to be rewritten!
int
create_volume(int volume_number, off_t size_in_blocks, CacheType scheme, CacheVol *cp)
{
static int curr_vol = 0; // FIXME: this will not reinitialize correctly
Suggested fix
Move curr_vol into the configuration-pass context (e.g. a parameter or a member of the object driving volume creation) so each (re)configuration starts from a defined cursor, then schedule the promised rewrite.
Filed from an automated multi-lens codebase audit. Full report: CODEBASE_AUDIT.md / audit-report.html on branch claude/codebase-audit-review-9nw7vz.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with create_volume() at src/iocore/cache/CacheProcessor.cc:1335 and read CODEBASE_AUDIT.md for the audit context. Trace the configuration-pass context that drives volume creation and determine how the static cursor is used across reconfigurations. Done means the cursor has defined state for each configuration pass and the cache stripe assignment no longer depends on prior configuration state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100