Skip to content

fix: race condition when creating standard logger - #68

Merged
aymanbagabas merged 1 commit into
mainfrom
write-race
Aug 1, 2023
Merged

aymanbagabas merged 1 commit into
mainfrom
write-race

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Jul 28, 2023 •

Copy link
Copy Markdown
Contributor

Before, StandardLog used to copy the internal buffer causing two or
more loggers to share the same buffer triggering a race.

Don't copy the internal buffer and reduce the mutex critical section
scope.

Fixes: #67

@codecov

codecov Bot commented Jul 28, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #68 (8254a5d) into main (280c4e3) will increase coverage by 0.64%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   76.85%   77.49%   +0.64%     
==========================================
  Files          10       10              
  Lines         635      631       -4     
==========================================
+ Hits          488      489       +1     
+ Misses        132      128       -4     
+ Partials       15       14       -1     
Files Changed Coverage Δ
logger.go 85.07% <100.00%> (+2.31%) ⬆️
stdlog.go 75.00% <100.00%> (-1.20%) ⬇️

@aymanbagabas aymanbagabas changed the title fix: lock buffer during write before read fix: race condition when creating standard logger Aug 1, 2023
@aymanbagabas
aymanbagabas requested a review from caarlos0 August 1, 2023 18:41
Before, `StandardLog` used to _copy_ the internal buffer causing two or
more loggers to share the same buffer triggering a race.

Don't copy the internal buffer and reduce the mutex critical section
scope.
@aymanbagabas
aymanbagabas merged commit 97dd8c9 into main Aug 1, 2023
@aymanbagabas
aymanbagabas deleted the write-race branch August 1, 2023 18:57
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

2 participants

⌂ 换网址