mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: wrap audit logs in a mutex to fix data race (#6898)
This was seen in `main`!
This commit is contained in:
+10
-2
@@ -39,13 +39,21 @@ func NewMock() *MockAuditor {
|
||||
|
||||
type MockAuditor struct {
|
||||
mutex sync.Mutex
|
||||
AuditLogs []database.AuditLog
|
||||
auditLogs []database.AuditLog
|
||||
}
|
||||
|
||||
func (a *MockAuditor) AuditLogs() []database.AuditLog {
|
||||
a.mutex.Lock()
|
||||
defer a.mutex.Unlock()
|
||||
logs := make([]database.AuditLog, len(a.auditLogs))
|
||||
copy(logs, a.auditLogs)
|
||||
return logs
|
||||
}
|
||||
|
||||
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
|
||||
a.mutex.Lock()
|
||||
defer a.mutex.Unlock()
|
||||
a.AuditLogs = append(a.AuditLogs, alog)
|
||||
a.auditLogs = append(a.auditLogs, alog)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user