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/[email protected]/output.go:162 +0xb4
  github.com/muesli/termenv.(*Output).BackgroundColor()
      /Users/vlad/go/pkg/mod/github.com/muesli/[email protected]/output.go:168 +0x78
  github.com/muesli/termenv.(*Output).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/muesli/[email protected]/output.go:176 +0x28
  github.com/charmbracelet/lipgloss.(*Renderer).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/renderer.go:116 +0x90
  github.com/charmbracelet/lipgloss.AdaptiveColor.color()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/style.go:257 +0x186c
  github.com/charmbracelet/bubbles/list.Model.statusView()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:1108 +0x320
  github.com/charmbracelet/bubbles/list.(*Model).updatePagination()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:722 +0x1dc
  github.com/charmbracelet/bubbles/list.(*Model).setSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:641 +0x170
  github.com/charmbracelet/bubbles/list.(*Model).SetSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/tea.go:373 +0x70c
  github.com/charmbracelet/bubbletea.(*Program).Run()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/logging/logging.go:46 +0x3a8
  github.com/charmbracelet/wish/activeterm.Middleware.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/activeterm/activeterm.go:21 +0x54
  github.com/charmbracelet/ssh.(*session).handleRequests.func1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/output.go:162 +0xb4
  github.com/muesli/termenv.(*Output).BackgroundColor()
      /Users/vlad/go/pkg/mod/github.com/muesli/[email protected]/output.go:168 +0x78
  github.com/muesli/termenv.(*Output).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/muesli/[email protected]/output.go:176 +0x28
  github.com/charmbracelet/lipgloss.(*Renderer).HasDarkBackground()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/renderer.go:116 +0x90
  github.com/charmbracelet/lipgloss.AdaptiveColor.color()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/style.go:257 +0x186c
  github.com/charmbracelet/bubbles/list.Model.statusView()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:1108 +0x320
  github.com/charmbracelet/bubbles/list.(*Model).updatePagination()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:722 +0x1dc
  github.com/charmbracelet/bubbles/list.(*Model).setSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/list/list.go:641 +0x170
  github.com/charmbracelet/bubbles/list.(*Model).SetSize()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/tea.go:373 +0x70c
  github.com/charmbracelet/bubbletea.(*Program).Run()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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/[email protected]/logging/logging.go:46 +0x3a8
  github.com/charmbracelet/wish/activeterm.Middleware.func1.1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/activeterm/activeterm.go:21 +0x54
  github.com/charmbracelet/ssh.(*session).handleRequests.func1()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/session.go:259 +0x4c

Goroutine 45 (running) created at:
  github.com/charmbracelet/ssh.(*session).handleRequests()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/session.go:258 +0x62c
  github.com/charmbracelet/ssh.DefaultSessionHandler()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/session.go:106 +0x2d8
  github.com/charmbracelet/ssh.(*Server).HandleConn.func4()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/server.go:305 +0x84

Goroutine 18 (running) created at:
  github.com/charmbracelet/ssh.(*session).handleRequests()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/session.go:258 +0x62c
  github.com/charmbracelet/ssh.DefaultSessionHandler()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/session.go:106 +0x2d8
  github.com/charmbracelet/ssh.(*Server).HandleConn.func4()
      /Users/vlad/go/pkg/mod/github.com/charmbracelet/[email protected]/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