Skip to content

fix: add mutex to MockAuditor export to prevent race #5189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: add mutex to MockAuditor export to prevent race
  • Loading branch information
kylecarbs committed Nov 30, 2022
commit a66d360a32e3b12cb6158a62ef393068f2501400
4 changes: 4 additions & 0 deletions coderd/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package audit

import (
"context"
"sync"

"github.com/coder/coder/coderd/database"
)
Expand Down Expand Up @@ -30,10 +31,13 @@ func NewMock() *MockAuditor {
}

type MockAuditor struct {
mutex sync.Mutex
AuditLogs []database.AuditLog
}

func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
a.mutex.Lock()
defer a.mutex.Unlock()
a.AuditLogs = append(a.AuditLogs, alog)
return nil
}
Expand Down