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 data race on set level and formatter #374

Closed
wants to merge 4 commits into from

Conversation

klizhentas
Copy link

fixes #295

logger.go Outdated
func (logger *Logger) formatter() Formatter {
logger.mu.RLock()
defer logger.mu.RUnlock()
return logger.Formatter
Copy link

Choose a reason for hiding this comment

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

You may avoid some overhead by not using defer as it is not strictly necessary here - reading a field can not panic and logger is not nil because it was accessed one line above. Same for the level() method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you could make the small adjustment to remove the defer and ping me, I'd be happy to merge this pull request.

Thanks for contributing this improvement!

Copy link
Author

Choose a reason for hiding this comment

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

@aarongreenlee I've addressed the code review comment

@klizhentas
Copy link
Author

@aarongreenlee ping

@aarongreenlee
Copy link
Collaborator

Thanks, @klizhentas. This all looks good to me. Can you please resolve these minor conflicts? I'll merge shortly thereafter.

Thanks for this contribution.

@johanbrandhorst
Copy link

@klizhentas pinging to have merge conflicts resolved. Good work!

@klizhentas
Copy link
Author

klizhentas commented Sep 14, 2016

I don't think it's actually possible to have my changeset to coexist with the master mostly because of this chunk of code that turns off locking:

https://github.com/Sirupsen/logrus/blob/master/logger.go#L53

https://github.com/Sirupsen/logrus/blob/master/logger.go#L306

Moreover I think the new MutexWrap introduces one more race condition on it's own - the disabled variable read/writes are not atomic and should be actually atomic operations. In addition to that in the new codebase there's theoretically could be a condition when you:

Lock()
SetNoLock()
Unlock()

getting a deadlock. Everyones ideas on getting this altogether are appreciated.

defer wg.Done()
switch i % 4 {
case 0:
SetLevel(InfoLevel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an equivalent (*Logger).SetLevel? It seems odd that this method would be at the package level but use a struct bound lock without offering the method on the struct itself.

@DmitriyMV DmitriyMV mentioned this pull request Mar 23, 2017
@DmitriyMV
Copy link
Contributor

I think it's partially fixed by #512, but Formatter problem remains. The mutex will prevent that but it will also introduce performance penalities in situations where the same log is used by several goroutines in parallel. Additional info here: golang/go#17973 TLDR - it doesn't scale well.

However, I'm still unconvinced that we really should bother about that in the first place, given the fact the most of the loggers and hooks are IO bound. Any thoughts on the matter? Synthetic benchmarks do not really show the realistic scenarios.

@klizhentas klizhentas closed this Nov 2, 2017
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.

Data Race in entry.go:128
7 participants