Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
NodeTypeZero = "zero"
)

var auditEnabled uint32
var auditEnabled atomic.Uint32

type AuditEvent struct {
User string
Expand Down Expand Up @@ -107,7 +107,7 @@ func InitAuditor(conf *x.LoggerConf, gId, nId uint64) error {
if auditor.log, err = x.InitLogger(conf, filename); err != nil {
return err
}
atomic.StoreUint32(&auditEnabled, 1)
auditEnabled.Store(1)
glog.Infoln("audit logs are enabled")
return nil
}
Expand All @@ -116,7 +116,7 @@ func InitAuditor(conf *x.LoggerConf, gId, nId uint64) error {
// It also sets the log to nil, because its being called by zero when license expires.
// If license added, InitLogger will take care of the file.
func Close() {
if atomic.LoadUint32(&auditEnabled) == 0 {
if auditEnabled.Load() == 0 {
return
}
auditor.log.Sync()
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The audit log is being synchronized but auditEnabled is not being reset to 0 after closing. This means the enabled check will continue to pass even after the auditor is closed, potentially causing nil pointer dereferences when trying to use the closed log.

Copilot uses AI. Check for mistakes.

Expand Down
6 changes: 3 additions & 3 deletions audit/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func AuditRequestGRPC(ctx context.Context, req interface{},
return skipApis[info.FullMethod[strings.LastIndex(info.FullMethod, "/")+1:]]
}

if atomic.LoadUint32(&auditEnabled) == 0 || skip(info.FullMethod) {
if auditEnabled.Load() == 0 || skip(info.FullMethod) {
return handler(ctx, req)
}
response, err := handler(ctx, req)
Expand All @@ -82,7 +82,7 @@ func AuditRequestHttp(next http.Handler) http.Handler {
return skipEPs[r.URL.Path]
}

if atomic.LoadUint32(&auditEnabled) == 0 || skip(r.URL.Path) {
if auditEnabled.Load() == 0 || skip(r.URL.Path) {
next.ServeHTTP(w, r)
return
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func AuditRequestHttp(next http.Handler) http.Handler {
}

func AuditWebSockets(ctx context.Context, req *schema.Request) {
if atomic.LoadUint32(&auditEnabled) == 0 {
if auditEnabled.Load() == 0 {
return
}

Expand Down
Loading