Skip to content

Add missing mutex to tail.reader usage#4829

Merged
kalleep merged 1 commit into
mainfrom
tail-race
Nov 13, 2025
Merged

Add missing mutex to tail.reader usage#4829
kalleep merged 1 commit into
mainfrom
tail-race

Conversation

@dehaansa
Copy link
Copy Markdown
Contributor

PR Description

Race detected in tests.

WARNING: DATA RACE
Read at 0x00c0057833b0 by goroutine 1267:
  bufio.(*Reader).Buffered()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:339 +0x1b2
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).Tell()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:136 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).markPositionAndSize()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:354 +0x3ee
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).stop()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:370 +0x46
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:186 +0x3f3
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:120 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[github.com/grafana/alloy/internal/component/common/loki/positions.Entry]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:116 +0x4a
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:50 +0x37
  sync.(*WaitGroup).Go.func1()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:239 +0x5d

Previous write at 0x00c0057833b0 by goroutine 1271:
  bufio.(*Reader).reset()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:88 +0x2c5
  bufio.(*Reader).Reset()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:84 +0x234
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).seekTo()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:397 +0x16f
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).tailFileSync()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:294 +0x3b8
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.TailFile.gowrap1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:109 +0x33

Goroutine 1267 (running) created at:
  sync.(*WaitGroup).Go()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:237 +0x86
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:49 +0x304
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).scheduleSources-range1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:342 +0x128f
  github.com/grafana/alloy/internal/component/loki/source/file.(*staticResolver).Resolve.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/resolver.go:45 +0x166
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).scheduleSources()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:290 +0x229
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).Update()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:278 +0x424
  github.com/grafana/alloy/internal/component/loki/source/file.New()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:169 +0x546
  github.com/grafana/alloy/internal/component/loki/source/file.init.0.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:32 +0x177
  github.com/grafana/alloy/internal/runtime/componenttest.(*Controller).buildComponent()
      /home/runner/work/alloy/alloy/internal/runtime/componenttest/componenttest.go:192 +0x527
  github.com/grafana/alloy/internal/runtime/componenttest.(*Controller).Run()
      /home/runner/work/alloy/alloy/internal/runtime/componenttest/componenttest.go:130 +0x131
  github.com/grafana/alloy/internal/component/loki/source/file.TestLegacyConversion.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/legacy_file_test.go:61 +0x3c8

Goroutine 1271 (running) created at:
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.TailFile()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:109 +0x4e4
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).initRun()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:229 +0xa3d
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:156 +0x79
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:120 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[github.com/grafana/alloy/internal/component/common/loki/positions.Entry]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:116 +0x4a
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:50 +0x37
  sync.(*WaitGroup).Go.func1()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:239 +0x5d
==================
==================
WARNING: DATA RACE
Read at 0x00c0057833a8 by goroutine 1267:
  bufio.(*Reader).Buffered()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:339 +0x1d0
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).Tell()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:136 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).markPositionAndSize()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:354 +0x3ee
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).stop()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:370 +0x46
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:186 +0x3f3
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:120 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[github.com/grafana/alloy/internal/component/common/loki/positions.Entry]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:116 +0x4a
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:50 +0x37
  sync.(*WaitGroup).Go.func1()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:239 +0x5d

Previous write at 0x00c0057833a8 by goroutine 1271:
  bufio.(*Reader).reset()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:88 +0x2c5
  bufio.(*Reader).Reset()
      /opt/hostedtoolcache/go/1.25.1/x64/src/bufio/bufio.go:84 +0x234
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).seekTo()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:397 +0x16f
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.(*Tail).tailFileSync()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:294 +0x3b8
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.TailFile.gowrap1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:109 +0x33

Goroutine 1267 (running) created at:
  sync.(*WaitGroup).Go()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:237 +0x86
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:49 +0x304
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).scheduleSources-range1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:342 +0x128f
  github.com/grafana/alloy/internal/component/loki/source/file.(*staticResolver).Resolve.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/resolver.go:45 +0x166
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).scheduleSources()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:290 +0x229
  github.com/grafana/alloy/internal/component/loki/source/file.(*Component).Update()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:278 +0x424
  github.com/grafana/alloy/internal/component/loki/source/file.New()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:169 +0x546
  github.com/grafana/alloy/internal/component/loki/source/file.init.0.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/file.go:32 +0x177
  github.com/grafana/alloy/internal/runtime/componenttest.(*Controller).buildComponent()
      /home/runner/work/alloy/alloy/internal/runtime/componenttest/componenttest.go:192 +0x527
  github.com/grafana/alloy/internal/runtime/componenttest.(*Controller).Run()
      /home/runner/work/alloy/alloy/internal/runtime/componenttest/componenttest.go:130 +0x131
  github.com/grafana/alloy/internal/component/loki/source/file.TestLegacyConversion.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/legacy_file_test.go:61 +0x3c8

Goroutine 1271 (running) created at:
  github.com/grafana/alloy/internal/component/loki/source/file/internal/tail.TailFile()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/internal/tail/tail.go:109 +0x4e4
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).initRun()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:229 +0xa3d
  github.com/grafana/alloy/internal/component/loki/source/file.(*tailer).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/tailer.go:156 +0x79
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:120 +0x178
  github.com/grafana/alloy/internal/component/loki/source/file.(*SourceWithRetry[github.com/grafana/alloy/internal/component/common/loki/positions.Entry]).Run()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:116 +0x4a
  github.com/grafana/alloy/internal/component/loki/source/file.(*Scheduler[go.shape.struct { Path string "yaml:\"path\""; Labels string "yaml:\"labels\"" }]).ScheduleSource.func1()
      /home/runner/work/alloy/alloy/internal/component/loki/source/file/scheduler.go:50 +0x37
  sync.(*WaitGroup).Go.func1()
      /opt/hostedtoolcache/go/1.25.1/x64/src/sync/waitgroup.go:239 +0x5d

@dehaansa dehaansa requested a review from a team as a code owner November 13, 2025 05:31
@dehaansa dehaansa changed the title Add mutex to missing tail.reader usage Add missing mutex to tail.reader usage Nov 13, 2025
@dehaansa dehaansa mentioned this pull request Nov 13, 2025
4 tasks
Copy link
Copy Markdown
Contributor

@kalleep kalleep left a comment

Choose a reason for hiding this comment

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

Thanks, there are for sure more issues around locking in this package. I have done some improvements to it but we need to review the package as a whole.

@kalleep kalleep merged commit 65fda47 into main Nov 13, 2025
41 checks passed
@kalleep kalleep deleted the tail-race branch November 13, 2025 08:32
dehaansa added a commit to madhub/alloy that referenced this pull request Dec 10, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants