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: added mutex around writes to logger struct for concurrent use of many… #269

Merged
merged 3 commits into from
Aug 10, 2021

Conversation

mateuszkowalke
Copy link
Contributor

@mateuszkowalke mateuszkowalke commented Aug 5, 2021

… clients

Closes #268

Proposed Changes

added mutex around logger struct

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are in semantic format
  • Sign CLA (if not already signed)

@mateuszkowalke mateuszkowalke changed the title added mutex around writes to logger struct for concurrent use of many… fix: added mutex around writes to logger struct for concurrent use of many… Aug 5, 2021
Copy link
Contributor

@vlastahajek vlastahajek left a comment

Choose a reason for hiding this comment

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

@mateuszkowalke, thanks for the issue and fix. Just a small change to complete this.

log/logger.go Outdated
type logger struct {
prefix string
logLevel uint
sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sync.Mutex
lock sync.Mutex

Logger has no functionality related to Mutex, so embedding (inheriting) is not needed.

log/logger.go Outdated
}

func (l *logger) SetLogLevel(logLevel uint) {
l.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
l.Lock()
l.lock.Lock()

log/logger.go Outdated
l.logLevel = logLevel
l.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
l.Unlock()
l.lock.Unlock()

log/logger.go Outdated
}

func (l *logger) LogLevel() uint {
return l.logLevel
}

func (l *logger) SetPrefix(prefix string) {
l.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
l.Lock()
l.lock.Lock()

log/logger.go Outdated
l.prefix = prefix
l.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
l.Unlock()
l.lock.Unlock()

@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2021

Codecov Report

Merging #269 (8692313) into master (083e8f4) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #269      +/-   ##
==========================================
- Coverage   91.78%   91.64%   -0.14%     
==========================================
  Files          23       23              
  Lines        1984     1988       +4     
==========================================
+ Hits         1821     1822       +1     
- Misses        108      111       +3     
  Partials       55       55              
Impacted Files Coverage Δ
log/logger.go 100.00% <100.00%> (ø)
api/tasks.go 92.52% <0.00%> (-1.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 083e8f4...8692313. Read the comment docs.

@vlastahajek vlastahajek merged commit 3e05cde into influxdata:master Aug 10, 2021
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.

Race condition on logger struct with multiple concurrent clients
3 participants