Data race on cursor.(*Model).BlinkCmd.func1
3v1n0 opened this issue · comments
Marco Trevisan commented
Describe the bug
A clear and concise description of what the bug is.
Setup
Please complete the following information along with version numbers, if applicable.
- OS: Ubuntu
- Shell zsh
- Terminal Emulator tilix
To Reproduce
In a test case where I'm sending events, I'm getting data races on blink commands
Source Code
Please include source code if needed to reproduce the behavior.
The previous write happened in the func (m *UIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
implementation of the main model where we have
m.userSelectionModel, cmd = m.userSelectionModel.Update(msg)
// where userSelectionModel is defined as `userSelectionMode{}`
type userSelectionModel struct {
textinput.Model
// ...
}
So basically writing to m.userSelectionModel
.
Trace
Read at 0x00c0006d86d8 by goroutine 385:
github.com/charmbracelet/bubbles/cursor.(*Model).BlinkCmd.func1()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbles@v0.17.1/cursor/cursor.go:168 +0x164
github.com/charmbracelet/bubbletea.(*Program).eventLoop.func1()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:381 +0x8c
Previous write at 0x00c0006d86d8 by goroutine 372:
github.com/ubuntu/authd/pam/internal/adapter.(*UIModel).Update()
/home/marco/Dev/authd/pam/internal/adapter/model.go:274 +0x2566
github.com/ubuntu/authd/pam/internal/adapter.(*mockUIModel).Update()
/home/marco/Dev/authd/pam/internal/adapter/gdmmodel_test.go:420 +0x65
github.com/charmbracelet/bubbletea.(*Program).eventLoop()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:411 +0xa3b
github.com/charmbracelet/bubbletea.(*Program).Run()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:543 +0xff6
github.com/ubuntu/authd/pam/internal/adapter.TestGdmModel.func5()
/home/marco/Dev/authd/pam/internal/adapter/gdmmodel_test.go:734 +0xc31
testing.tRunner()
/snap/go/10489/src/testing/testing.go:1595 +0x261
testing.(*T).Run.func1()
/snap/go/10489/src/testing/testing.go:1648 +0x44
Goroutine 385 (running) created at:
github.com/charmbracelet/bubbletea.(*Program).eventLoop()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:374 +0x4cb
github.com/charmbracelet/bubbletea.(*Program).Run()
/tmp/go-path/pkg/mod/github.com/charmbracelet/bubbletea@v0.25.0/tea.go:543 +0xff6
github.com/ubuntu/authd/pam/internal/adapter.TestGdmModel.func5()
/home/marco/Dev/authd/pam/internal/adapter/gdmmodel_test.go:734 +0xc31
testing.tRunner()
/snap/go/10489/src/testing/testing.go:1595 +0x261
testing.(*T).Run.func1()
/snap/go/10489/src/testing/testing.go:1648 +0x44
Goroutine 372 (finished) created at:
testing.(*T).Run()
/snap/go/10489/src/testing/testing.go:1648 +0x845
github.com/ubuntu/authd/pam/internal/adapter.TestGdmModel()
/home/marco/Dev/authd/pam/internal/adapter/gdmmodel_test.go:644 +0x13ef
testing.tRunner()
/snap/go/10489/src/testing/testing.go:1595 +0x261
testing.(*T).Run.func1()
/snap/go/10489/src/testing/testing.go:1648 +0x44
Workaround is to avoid blinking... So using textinput.Model.Cursor.SetMode(cursor.CursorHide)
.