Skip to content

Commit 4e54ce2

Browse files
kylecarbspull[bot]
authored andcommitted
fix: add mutex to MockAuditor export to prevent race (#5189)
See: https://github.com/coder/coder/actions/runs/3575201153/jobs/6011435900.
1 parent ddc7e75 commit 4e54ce2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

coderd/audit/audit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package audit
22

33
import (
44
"context"
5+
"sync"
56

67
"github.com/coder/coder/coderd/database"
78
)
@@ -30,10 +31,13 @@ func NewMock() *MockAuditor {
3031
}
3132

3233
type MockAuditor struct {
34+
mutex sync.Mutex
3335
AuditLogs []database.AuditLog
3436
}
3537

3638
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
39+
a.mutex.Lock()
40+
defer a.mutex.Unlock()
3741
a.AuditLogs = append(a.AuditLogs, alog)
3842
return nil
3943
}

0 commit comments

Comments
 (0)