Skip to content

Commit 48fc384

Browse files
committed
protected user map on request with mutex
1 parent 942437f commit 48fc384

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

coderd/httpmw/loggermw/logger.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"sync"
78
"time"
89

910
"cdr.dev/slog"
@@ -71,6 +72,7 @@ type SlogRequestLogger struct {
7172
written bool
7273
message string
7374
start time.Time
75+
mu sync.RWMutex
7476
actors map[rbac.SubjectType]rbac.Subject
7577
}
7678

@@ -91,10 +93,15 @@ func (c *SlogRequestLogger) WithFields(fields ...slog.Field) {
9193
}
9294

9395
func (c *SlogRequestLogger) WithAuthContext(actor rbac.Subject) {
96+
c.mu.Lock()
97+
defer c.mu.Unlock()
9498
c.actors[actor.Type] = actor
9599
}
96100

97101
func (c *SlogRequestLogger) addAuthContextFields() {
102+
c.mu.RLock()
103+
defer c.mu.RUnlock()
104+
98105
usr, ok := c.actors[rbac.SubjectTypeUser]
99106
if ok {
100107
c.log = c.log.With(

0 commit comments

Comments
 (0)