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

fix: race condition on repaint #330

Merged
merged 1 commit into from Jun 4, 2022

Conversation

geodimm
Copy link
Contributor

@geodimm geodimm commented Jun 4, 2022

I noticed that there's a race condition when resizing windows. It's happening because the main tea Program loop calls repaint()

p.renderer.repaint()

and the renderer is also setting the value of its lastRender:

r.lastRender = r.buf.String()

This can be reproduced with the textinput example. Simply run it and resize your terminal window.

Output:

$ go run -race test.go
What’s your favorite Pokémon?

> Pikachu

(esc to quit)
==================
WARNING: DATA RACE
Write at 0x00c00014c198 by main goroutine:
  github.com/charmbracelet/bubbletea.(*standardRenderer).repaint()
      my-project/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go:233 +0x39
  github.com/charmbracelet/bubbletea.(*Program).StartReturningModel()
      my-project/vendor/github.com/charmbracelet/bubbletea/tea.go:506 +0x1b17
  github.com/charmbracelet/bubbletea.(*Program).Start()
      my-project/vendor/github.com/charmbracelet/bubbletea/tea.go:547 +0xa4
  main.main()
      my-project/main.go:14 +0xa5

Previous write at 0x00c00014c198 by goroutine 9:
  github.com/charmbracelet/bubbletea.(*standardRenderer).flush()
      my-project/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go:210 +0xd04
  github.com/charmbracelet/bubbletea.(*standardRenderer).listen()
      my-project/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go:101 +0x124
  github.com/charmbracelet/bubbletea.(*standardRenderer).start.func1()
      my-project/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go:69 +0x39

Goroutine 9 (running) created at:
  github.com/charmbracelet/bubbletea.(*standardRenderer).start()
      my-project/vendor/github.com/charmbracelet/bubbletea/standard_renderer.go:69 +0x156
  github.com/charmbracelet/bubbletea.(*Program).StartReturningModel()
      my-project/vendor/github.com/charmbracelet/bubbletea/tea.go:413 +0xda1
What’s your favorite Pokémon?

> Pikachu

(esc to quit)

@muesli
Copy link
Member

muesli commented Jun 4, 2022

Great find. We should probably enable the race detector in the CI.

@muesli muesli added the bug Something isn't working label Jun 4, 2022
@muesli muesli merged commit 50a8461 into charmbracelet:master Jun 4, 2022
@geodimm geodimm deleted the fix-renderer-race branch June 4, 2022 14:56
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

Successfully merging this pull request may close these issues.

None yet

3 participants