Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race on pterm.SpinnerPrinter #482

Open
KirillSerebryakov123 opened this issue Apr 4, 2023 · 2 comments
Open

Data race on pterm.SpinnerPrinter #482

KirillSerebryakov123 opened this issue Apr 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@KirillSerebryakov123
Copy link

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

@KirillSerebryakov123 KirillSerebryakov123 added the bug Something isn't working label Apr 4, 2023
@MarvinJWendt
Copy link
Member

Hi @KirillSerebryakov123, thanks for reporting! This should get fixed with #447 :)

@jsteenb2
Copy link

hey all, any update here?

I'm seeing the same issue running go 1.21 with the github.com/pterm/pterm@v0.12.79 module and seeing errors when go test is invoked with -race. I'm using the multiwriter, and it seems to be hitting the race conditions within the spinners that are created with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants