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 #145

Open
VladyslavLukyanenko opened this issue Jul 28, 2023 · 0 comments · May be fixed by #146
Open

Data race #145

VladyslavLukyanenko opened this issue Jul 28, 2023 · 0 comments · May be fixed by #146

Comments

@VladyslavLukyanenko
Copy link

WARNING: DATA RACE
Write at 0x00c0001b8170 by goroutine 45:
  github.com/muesli/termenv.(*Output).BackgroundColor.func1()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:162 +0xb4
  github.com/muesli/termenv.(*Output).BackgroundColor()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:168 +0x78
  github.com/muesli/termenv.(*Output).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:176 +0x28
  github.com/charmbracelet/lipgloss.(*Renderer).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/renderer.go:116 +0x90
  github.com/charmbracelet/lipgloss.AdaptiveColor.color()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/color.go:100 +0x80
  github.com/charmbracelet/lipgloss.(*AdaptiveColor).color()
      <autogenerated>:1 +0x64
  github.com/charmbracelet/lipgloss.Style.Render()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/style.go:257 +0x186c
  github.com/charmbracelet/bubbles/list.Model.statusView()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:1108 +0x320
  github.com/charmbracelet/bubbles/list.(*Model).updatePagination()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:722 +0x1dc
  github.com/charmbracelet/bubbles/list.(*Model).setSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:641 +0x170
  github.com/charmbracelet/bubbles/list.(*Model).SetSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:621 +0xa80
  github.com/charmbracelet/wishlist.(*ListModel).Update()
      /Users/vlad/TestArea/wishlist/wishlist.go:153 +0xa5c
  github.com/charmbracelet/bubbletea.(*Program).eventLoop()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:373 +0x70c
  github.com/charmbracelet/bubbletea.(*Program).Run()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:503 +0xaf0
  github.com/charmbracelet/wishlist.listingMiddleware.func1.1()
      /Users/vlad/TestArea/wishlist/middleware.go:78 +0x574
  github.com/charmbracelet/wishlist.cmdsMiddleware.func1.1()
      /Users/vlad/TestArea/wishlist/middleware.go:29 +0x188
  github.com/charmbracelet/wish/logging.MiddlewareWithLogger.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/wish@v1.1.1/logging/logging.go:46 +0x3a8
  github.com/charmbracelet/wish/activeterm.Middleware.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/wish@v1.1.1/activeterm/activeterm.go:21 +0x54
  github.com/charmbracelet/ssh.(*session).handleRequests.func1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:259 +0x4c

Previous write at 0x00c0001b8170 by goroutine 18:
  github.com/muesli/termenv.(*Output).BackgroundColor.func1()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:162 +0xb4
  github.com/muesli/termenv.(*Output).BackgroundColor()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:168 +0x78
  github.com/muesli/termenv.(*Output).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/muesli/termenv@v0.15.2/output.go:176 +0x28
  github.com/charmbracelet/lipgloss.(*Renderer).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/renderer.go:116 +0x90
  github.com/charmbracelet/lipgloss.AdaptiveColor.color()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/color.go:100 +0x80
  github.com/charmbracelet/lipgloss.(*AdaptiveColor).color()
      <autogenerated>:1 +0x64
  github.com/charmbracelet/lipgloss.Style.Render()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/lipgloss@v0.7.1/style.go:257 +0x186c
  github.com/charmbracelet/bubbles/list.Model.statusView()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:1108 +0x320
  github.com/charmbracelet/bubbles/list.(*Model).updatePagination()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:722 +0x1dc
  github.com/charmbracelet/bubbles/list.(*Model).setSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:641 +0x170
  github.com/charmbracelet/bubbles/list.(*Model).SetSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/list/list.go:621 +0xa80
  github.com/charmbracelet/wishlist.(*ListModel).Update()
      /Users/vlad/TestArea/wishlist/wishlist.go:153 +0xa5c
  github.com/charmbracelet/bubbletea.(*Program).eventLoop()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:373 +0x70c
  github.com/charmbracelet/bubbletea.(*Program).Run()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:503 +0xaf0
  github.com/charmbracelet/wishlist.listingMiddleware.func1.1()
      /Users/vlad/TestArea/wishlist/middleware.go:78 +0x574
  github.com/charmbracelet/wishlist.cmdsMiddleware.func1.1()
      /Users/vlad/TestArea/wishlist/middleware.go:29 +0x188
  github.com/charmbracelet/wish/logging.MiddlewareWithLogger.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/wish@v1.1.1/logging/logging.go:46 +0x3a8
  github.com/charmbracelet/wish/activeterm.Middleware.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/wish@v1.1.1/activeterm/activeterm.go:21 +0x54
  github.com/charmbracelet/ssh.(*session).handleRequests.func1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:259 +0x4c

Goroutine 45 (running) created at:
  github.com/charmbracelet/ssh.(*session).handleRequests()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:258 +0x62c
  github.com/charmbracelet/ssh.DefaultSessionHandler()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:106 +0x2d8
  github.com/charmbracelet/ssh.(*Server).HandleConn.func4()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/server.go:305 +0x84

Goroutine 18 (running) created at:
  github.com/charmbracelet/ssh.(*session).handleRequests()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:258 +0x62c
  github.com/charmbracelet/ssh.DefaultSessionHandler()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/session.go:106 +0x2d8
  github.com/charmbracelet/ssh.(*Server).HandleConn.func4()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/ssh@v0.0.0-20221117183211-483d43d97103/server.go:305 +0x84
==================

Running currently latest wishlist serve with race flag, and connecting multiple clients to the server, then as i move the terminal data race happens

aymanbagabas added a commit that referenced this issue Jul 28, 2023
Make output profile accessible through `ColorProfile`.
Use `SetColorProfile` to change the output color profile.
Use a mutex to guard output writes.

Fixes: charmbracelet/lipgloss#210
Fixes: #145
@aymanbagabas aymanbagabas linked a pull request Jul 28, 2023 that will close this issue
aymanbagabas added a commit that referenced this issue Jul 28, 2023
Make output profile accessible through `ColorProfile`.
Use `SetColorProfile` to change the output color profile.
Use a mutex to guard output writes.
Use pointer receiver

Fixes: charmbracelet/lipgloss#210
Fixes: #145
aymanbagabas added a commit that referenced this issue Jul 28, 2023
BREAKING!

`ColorProfile` reads the terminal environment every time the function is
called. This is inefficient. We only need to read the `$TERM`
environment variable once when we initialize the output. So we cache
the value we read.

Rename `ColorProfile` to `termColorProfile` and rely on
`EnvColorProfile` to detect the profile. Ideally, we rely on the
terminal Terminfo to detect the profile and fallback to the environment.

Make output profile accessible through `ColorProfile`.
Use `SetColorProfile` to change the output color profile.
Use a mutex to guard output writes.
Use pointer receiver since we have a lock in the struct

Fixes: charmbracelet/lipgloss#210
Fixes: #145
aymanbagabas added a commit that referenced this issue Jul 28, 2023
`ColorProfile` reads the terminal environment every time the function is
called. This is inefficient. We only need to read the `$TERM`
environment variable once when we initialize the output. So instead, we cache
the value we read.

Rename `ColorProfile` to `termColorProfile` and rely on
`EnvColorProfile` to detect the profile. Ideally, we would rely on the
terminal Terminfo to detect the profile and fallback to the environment.
But that's for another day :)

Make output profile accessible through `ColorProfile`.
Use `SetColorProfile` to change the output color profile.
Use a mutex to guard output writes.
Use pointer receiver since we have a lock in the struct

Fixes: charmbracelet/lipgloss#210
Fixes: #145
aymanbagabas added a commit that referenced this issue Jul 28, 2023
`ColorProfile` reads the terminal environment every time the function is
called. This is inefficient. We only need to read the `$TERM`
environment variable once when we initialize the output. So instead, we cache
the value we read.

Rename `ColorProfile` to `termColorProfile` and rely on
`EnvColorProfile` to detect the profile. Ideally, we would rely on the
terminal Terminfo to detect the profile and fallback to the environment.
But that's for another day :)

Make output profile accessible through `ColorProfile`.
Use `SetColorProfile` to change the output color profile.
Use a mutex to guard output writes.
Use pointer receiver since we have a lock in the struct

Fixes: charmbracelet/lipgloss#210
Fixes: #145
aymanbagabas added a commit that referenced this issue Jul 28, 2023
Use a mutex to guard setting/getting the color profile and fg/bg colors.
Use `SetColorProfile` to change the output color profile.
Use pointer receiver since we have a lock in the struct.

Fixes: charmbracelet/lipgloss#210
Fixes: #145
aymanbagabas added a commit that referenced this issue Jul 28, 2023
Use a mutex to guard setting/getting the color profile and fg/bg colors.
Use `SetColorProfile` to change the output color profile.
Use pointer receiver since we have a lock in the struct.

Fixes: charmbracelet/lipgloss#210
Fixes: #145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant