-
-
Notifications
You must be signed in to change notification settings - Fork 616
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: use a sync.Map to prevent "concurrent map read and map write" fa… #1923
base: main
Are you sure you want to change the base?
Conversation
…tal error when using "output: prefixed"
@@ -85,11 +86,11 @@ func (pw *prefixWriter) writeLine(line string) error { | |||
line += "\n" | |||
} | |||
|
|||
idx, ok := pw.prefixed.seen[pw.prefix] | |||
idx, ok := pw.prefixed.seen.Load(pw.prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps LoadOrStore() is better than Load() and then Store()?
|
||
"github.com/go-task/task/v3/internal/logger" | ||
"github.com/go-task/task/v3/internal/templater" | ||
) | ||
|
||
type Prefixed struct { | ||
logger *logger.Logger | ||
seen map[string]uint | ||
seen *sync.Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simply use a mutex for protecting the seen
map? It's actively used in this project: 1, 2.
seen *sync.Map | |
muSeen sync.Mutex | |
seen map[string]uint |
Additionally, sync.Map
has drawbacks and rare use cases. See https://victoriametrics.com/blog/go-sync-map/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we need to add a test case to ensure that this PR fixes an issue.
…tal error when using "output: prefixed"
fixes #1922