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: concurrent mutations to prefixWriter #1974

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/output/prefixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"strings"
"sync"

"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/templater"
Expand All @@ -14,6 +15,7 @@ type Prefixed struct {
logger *logger.Logger
seen map[string]uint
counter *uint
mutex *sync.Mutex
}

func NewPrefixed(logger *logger.Logger) Prefixed {
Expand All @@ -23,6 +25,7 @@ func NewPrefixed(logger *logger.Logger) Prefixed {
seen: make(map[string]uint),
counter: &counter,
logger: logger,
mutex: &sync.Mutex{},
}
}

Expand Down Expand Up @@ -85,6 +88,9 @@ func (pw *prefixWriter) writeLine(line string) error {
line += "\n"
}

defer pw.prefixed.mutex.Unlock()
pw.prefixed.mutex.Lock()

idx, ok := pw.prefixed.seen[pw.prefix]

if !ok {
Expand Down
Loading