Skip to content
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

Fix SetLevel data-race #512

Merged
merged 1 commit into from May 12, 2017
Merged

Conversation

DmitriyMV
Copy link
Contributor

From #374.

The commit fixes data race using atomics Load\Save. We switch type of level from uint8 to uint32 but due memory alignment on most platforms it will not result in any additional memory. This can actually be a breaking change if you store Level somewhere in your code. The alternative would be creating a new type and using it inside Logger struct. On package boundaries we could convert it from existing Level silently.

…om uint8 to uint32 but due memory alignment on most platforms it will not result in any additional memory.
@sirupsen
Copy link
Owner

sirupsen commented May 4, 2017

Why is there a race here if there's a lock in setLevel? I'm assuming because every log outputting doesn't actually grab the lock?

@DmitriyMV
Copy link
Contributor Author

Exactly - if we try to set a different level and concurrent goroutine will try to write a log - we will get datarace.

@sirupsen sirupsen merged commit 2c677e6 into sirupsen:master May 12, 2017
@sirupsen
Copy link
Owner

Thanks for the fix!

This was referenced May 15, 2017
cgxxv pushed a commit to cgxxv/logrus that referenced this pull request Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants