JakeChampion / JakeChampion/trafficserver

[audit][cache] create_volume: self-declared 'really bad code' with a function-local static that breaks reinitialization

Open
#53 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cache audit severity:medium
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.