Skip to content

fix(log): make global logger thread-safe with atomic.Pointer#155

Merged
skevetter merged 1 commit into
mainfrom
fix/logger-race-safety
Apr 26, 2026
Merged

fix(log): make global logger thread-safe with atomic.Pointer#155
skevetter merged 1 commit into
mainfrom
fix/logger-race-safety

Conversation

@skevetter

Copy link
Copy Markdown
Contributor

Summary

The global sugar variable in pkg/log/logger.go was an unprotected *zap.SugaredLogger pointer. Concurrent reads from log functions (e.g. log.Debug() in deferred calls in pkg/inject/inject.go) and writes from test cleanup (t.Cleanup restoring sugar in pkg/log/testing.go) caused data races detected by Go's race detector in CI run 24964563286.

The race was introduced by #147, which added defer log.Debug(...) calls in inject.go that fire after goroutines send to channels — creating concurrent access with test cleanup writing to sugar.

This replaces the bare *zap.SugaredLogger pointer with atomic.Pointer[zap.SugaredLogger]. All reads go through sugar.Load() and all writes through sugar.Store(), making the global logger safe for concurrent access with zero behavioral changes.

Files changed: pkg/log/logger.go, pkg/log/testing.go, pkg/log/levels.go, pkg/log/writer.go

@netlify

netlify Bot commented Apr 26, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit e70f82f
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/69ee7e18f843f800084e7390

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@skevetter has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 22 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 33 minutes and 22 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f192d776-1389-4c97-aa4f-248a846f8368

📥 Commits

Reviewing files that changed from the base of the PR and between e060069 and e70f82f.

📒 Files selected for processing (4)
  • pkg/log/levels.go
  • pkg/log/logger.go
  • pkg/log/testing.go
  • pkg/log/writer.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@skevetter
skevetter merged commit 7fdb0f4 into main Apr 26, 2026
81 of 88 checks passed
@skevetter
skevetter deleted the fix/logger-race-safety branch April 26, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant