Skip to content

Data race on pterm.SpinnerPrinter #482

@KirillSerebryakov123

Description

@KirillSerebryakov123

Hello.

I have identified a data race on the pterm.SpinnerPrinter.

General information:

  • pterm version: v0.12.57
  • go version: v1.19.7
  • os: windows

Steps to reproduce:
run following code with go run -race

p, err := pterm.DefaultSpinner.
    WithShowTimer(false).
    WithRemoveWhenDone(true).
    Start("Doing stuff...")

if err != nil {
    log.Fatalf("Start spinner failed: %s", err.Error())
}

time.Sleep(2 * time.Second)

err = p.Stop()
if err != nil {
    log.Fatalf("Stop spinner failed: %s", err.Error())
}

After inspecting the source code i have found out that the reason is the go routine, spawned in func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error)

func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error) {
A new routine is being started within this method, which reads the IsActive field.
for s.IsActive {
func (s *SpinnerPrinter) Stop() error writes to this field from anothe routine, and this causes a data race.
s.IsActive = false

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions