Skip to content

fix(inputs.tail): Fix data race when cleaning up unused tailers#17613

Merged
mstrandboge merged 5 commits into
influxdata:masterfrom
skartikey:inputs_tail_data_race_fix
Sep 12, 2025
Merged

fix(inputs.tail): Fix data race when cleaning up unused tailers#17613
mstrandboge merged 5 commits into
influxdata:masterfrom
skartikey:inputs_tail_data_race_fix

Conversation

@skartikey
Copy link
Copy Markdown
Contributor

Summary

Fixes a critical data race condition in the tail input plugin that was blocking multiple dependency updates due to increased detection frequency with testify v1.11.x.

The race condition occurred in cleanupUnusedTailers() between:

  • The telegraf tail plugin calling Tell() to get the current file offset
  • The tail library's internal goroutine calling reopen() which modifies the file handle

Solution

Removed the Tell() call during cleanup of tailers for files that no longer match glob patterns. This is a safe trade-off because:

  1. Files removed from glob patterns are typically rotated logs (e.g., app.logapp.log.1) that won't return with the same name
  2. The Stop() method still saves offsets when the plugin stops normally, preserving the primary use case
  3. Eliminates the race condition entirely rather than trying to work around it

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #17571

Remove Tell() call during tailer cleanup to avoid race condition with the tail library's internal file reopening goroutine. The race occurred when Tell() tried to read the file handle while the tail library was
  concurrently modifying it during reopen().
This fix prioritizes stability by not saving offsets for files that no longer match glob patterns, as these are typically rotated logs that won't return with the same name.

Fixes influxdata#17571
@telegraf-tiger telegraf-tiger Bot added area/tail fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Sep 9, 2025
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks @skartikey! One question in the code...

Comment thread plugins/inputs/tail/tail.go Outdated
… preserve offsets

Stop the tailer before calling Tell() during cleanup to eliminate the race condition while still preserving file offsets for state persistence. This ensures that files temporarily removed from glob patterns can resume from the correct position if they return.
@srebhan srebhan changed the title fix(inputs.tail): Fix data race in cleanupUnusedTailers fix(inputs.tail): Fix data race when cleaning up unused tailers Sep 10, 2025
Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks for the update @skartikey! Looks good to me, just some style comments...

Comment thread plugins/inputs/tail/tail.go Outdated
Comment thread plugins/inputs/tail/tail.go Outdated
skartikey and others added 3 commits September 10, 2025 15:32
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
@telegraf-tiger
Copy link
Copy Markdown
Contributor

Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip.
Downloads for additional architectures and packages are available below.

☺️ This pull request doesn't significantly change the Telegraf binary size (less than 1%)

📦 Click here to get additional PR build artifacts

Artifact URLs

. DEB . RPM . TAR . GZ . ZIP
[[amd64.deb aarch64.rpm darwin_amd64.tar.gz windows_amd64.zip] [arm64.deb armel.rpm darwin_arm64.tar.gz windows_arm64.zip] [armel.deb armv6hl.rpm freebsd_amd64.tar.gz windows_i386.zip] [armhf.deb i386.rpm freebsd_armv7.tar.gz ] [i386.deb ppc64le.rpm freebsd_i386.tar.gz ] [mips.deb riscv64.rpm linux_amd64.tar.gz ] [mipsel.deb s390x.rpm linux_arm64.tar.gz ] [ppc64el.deb x86_64.rpm linux_armel.tar.gz ] [riscv64.deb linux_armhf.tar.gz ] [s390x.deb linux_i386.tar.gz ] [ linux_mips.tar.gz ] [ linux_mipsel.tar.gz ] [ linux_ppc64le.tar.gz ] [ linux_riscv64.tar.gz ] [ linux_s390x.tar.gz ]]

Copy link
Copy Markdown
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thanks @skartikey!

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Sep 10, 2025
@srebhan srebhan assigned mstrandboge and unassigned srebhan Sep 10, 2025
@mstrandboge mstrandboge merged commit 2586690 into influxdata:master Sep 12, 2025
25 of 26 checks passed
@github-actions github-actions Bot added this to the v1.36.2 milestone Sep 12, 2025
srebhan added a commit that referenced this pull request Sep 29, 2025
Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
(cherry picked from commit 2586690)
skartikey added a commit to skartikey/telegraf that referenced this pull request Sep 30, 2025
…uxdata#17613)

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tail fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in tail input tests

3 participants