Skip to content

Commit

Permalink
fix: concurrent mutations to prefixWriter (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDennis authored Dec 30, 2024
1 parent fd35328 commit 0409c3c
Showing 1 changed file with 6 additions and 0 deletions.
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

0 comments on commit 0409c3c

Please sign in to comment.