Skip to content

fix: data race in progress bar field access (Placeholder/Complete/Abort) #469

@aftersnow

Description

@aftersnow

Description

The Placeholder(), Complete(), and Abort() methods in internal/pb/pb.go modify bar.msg after releasing RLock, which can race with the progress bar rendering goroutine that reads bar.msg concurrently.

Example in Placeholder():

p.mu.RLock()
existing := p.bars[name]
p.mu.RUnlock()

if existing != nil {
    existing.msg = ...  // write without lock, concurrent read by renderer
}

The same pattern exists in Complete() (line 177) and Abort().

Suggested Fix

Use a write lock (p.mu.Lock()) when modifying bar.msg, or add a per-bar mutex to protect field access.

Context

Found during code review of #468. This is a pre-existing issue, not introduced by that PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions