You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
Fix race in server LogEntry logger (#6449)
This commit is contained in:
+10
-9
@@ -67,6 +67,12 @@ func New() Log {
|
||||
|
||||
func (l *logger) Open(_ context.Context, stepID int64) error {
|
||||
l.Lock()
|
||||
l.open(stepID)
|
||||
l.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *logger) open(stepID int64) {
|
||||
_, ok := l.streams[stepID]
|
||||
if !ok {
|
||||
l.streams[stepID] = &stream{
|
||||
@@ -75,23 +81,18 @@ func (l *logger) Open(_ context.Context, stepID int64) error {
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
l.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *logger) Write(ctx context.Context, stepID int64, entries []*model.LogEntry) error {
|
||||
l.Lock()
|
||||
s, ok := l.streams[stepID]
|
||||
l.Unlock()
|
||||
|
||||
// auto open the stream if it does not exist
|
||||
if !ok {
|
||||
err := l.Open(ctx, stepID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Auto-open the stream while still holding the logger lock so that a
|
||||
// concurrent Write for the same step cannot race on l.streams.
|
||||
l.open(stepID)
|
||||
s = l.streams[stepID]
|
||||
}
|
||||
l.Unlock()
|
||||
|
||||
s.Lock()
|
||||
s.list = append(s.list, entries...)
|
||||
|
||||
Reference in New Issue
Block a user