Race conditions detected
While investigating https://gitlab.com/gitlab-com/gl-infra/reliability/-/issues/16954 and gitlab-org/gitlab#423382 (comment 1536313310), I built gitlab-logger
with -race
and found these race conditions:
==================
WARNING: DATA RACE
Read at 0x00c000014010 by goroutine 26:
main.tail.func1()
/home/stanhu/gitlab/gitlab-logger/main.go:350 +0x14f
Previous write at 0x00c000014010 by goroutine 7:
main.tail()
/home/stanhu/gitlab/gitlab-logger/main.go:342 +0x84
main.main.func2()
/home/stanhu/gitlab/gitlab-logger/main.go:181 +0x39
Goroutine 26 (running) created at:
main.tail()
/home/stanhu/gitlab/gitlab-logger/main.go:345 +0x236
main.main.func2()
/home/stanhu/gitlab/gitlab-logger/main.go:181 +0x39
Goroutine 7 (running) created at:
main.main()
/home/stanhu/gitlab/gitlab-logger/main.go:181 +0x1a4
==================
==================
WARNING: DATA RACE
Read at 0x00c000180008 by goroutine 26:
main.tail.func1()
/home/stanhu/gitlab/gitlab-logger/main.go:350 +0x170
Previous write at 0x00c000180008 by goroutine 9:
main.watch.func1()
/home/stanhu/gitlab/gitlab-logger/main.go:317 +0x345
Goroutine 26 (running) created at:
main.tail()
/home/stanhu/gitlab/gitlab-logger/main.go:345 +0x236
main.main.func2()
/home/stanhu/gitlab/gitlab-logger/main.go:181 +0x39
Goroutine 9 (running) created at:
main.watch()
/home/stanhu/gitlab/gitlab-logger/main.go:309 +0x148
main.main.func3()
/home/stanhu/gitlab/gitlab-logger/main.go:183 +0x64
==================
==================
WARNING: DATA RACE
Read at 0x00c000180020 by goroutine 26:
main.tail.func1()
/home/stanhu/gitlab/gitlab-logger/main.go:354 +0x1fb
Previous write at 0x00c000180020 by goroutine 9:
main.watch.func1()
/home/stanhu/gitlab/gitlab-logger/main.go:317 +0x345
Goroutine 26 (running) created at:
main.tail()
/home/stanhu/gitlab/gitlab-logger/main.go:345 +0x236
main.main.func2()
/home/stanhu/gitlab/gitlab-logger/main.go:181 +0x39
Goroutine 9 (running) created at:
main.watch()
/home/stanhu/gitlab/gitlab-logger/main.go:309 +0x148
main.main.func3()
/home/stanhu/gitlab/gitlab-logger/main.go:183 +0x64
==================
I used this script:
threads = []
10.times do |index|
threads << Thread.new do
data = File.open('performance_bar_json.log')
output = File.open("test/output#{index}.log", 'a')
sleep 1
lines = data.readlines
lines.each do |line|
sleep (rand(200) / 1000.0)
output.write(line)
end
end
end
threads.map(&:join)