Skip to content

[8.19](backport #51570) filestream: Fix date sorter short path panic#51606

Merged
orestisfl merged 1 commit into
8.19from
mergify/bp/8.19/pr-51570
Jun 29, 2026
Merged

[8.19](backport #51570) filestream: Fix date sorter short path panic#51606
orestisfl merged 1 commit into
8.19from
mergify/bp/8.19/pr-51570

Conversation

@mergify

@mergify mergify Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Proposed commit message

Fix filestream date sorter short path panic

Return a zero timestamp when a rotated file path is shorter than the configured
date format so copytruncate sorting cannot panic inside the prospector
goroutine.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None

How to test this PR locally

go test -race ./filebeat/input/filestream/...

Real reproduction:

rm -rf /tmp/fbr /tmp/fbr-home-fixed
mkdir -p /tmp/fbr /tmp/fbr-home-fixed
python - <<'PY'
from pathlib import Path
base = Path('/tmp/fbr')
for name, prefix in [('a', 'original'), ('a-1', 'rotated-one'), ('a-2', 'rotated-two')]:
    with (base / name).open('w') as f:
        for i in range(140):
            f.write(f'{prefix} line {i:03d} abcdefghijklmnopqrstuvwxyz\n')
PY
cat >/tmp/fbr-filebeat.yml <<'YAML'
filebeat.inputs:
  - type: filestream
    id: repro-copytruncate-datesort
    paths:
      - /tmp/fbr/*
    prospector.scanner.check_interval: 1s
    rotation:
      external:
        strategy:
          copytruncate:
            suffix_regex: '-\d$'
            dateformat: '2006-01-02T15:04:05.000000Z07:00'

output.console:
  enabled: true
  codec.format:
    string: 'EVENT: %{[message]}'

logging.level: debug
logging.to_stderr: true

queue.mem:
  flush.timeout: 0s
YAML

timeout 5 /tmp/filebeat-fixed -e --strict.perms=false -c /tmp/fbr-filebeat.yml --path.home=/tmp/fbr-home-fixed > /tmp/fbr-fixed.log 2>&1
grep 'File /tmp/fbr/a-2 is rotated' /tmp/fbr-fixed.log
grep 'EVENT:' /tmp/fbr-fixed.log
grep -E 'panic|slice bounds out of range' /tmp/fbr-fixed.log

On an unpatched build, the same config exits with a panic after detecting /tmp/fbr/a-2 as rotated:

panic: runtime error: slice bounds out of range [-20:]
github.com/elastic/beats/v7/filebeat/input/filestream.(*dateSorter).GetTs
github.com/elastic/beats/v7/filebeat/input/filestream.(*dateSorter).sort
github.com/elastic/beats/v7/filebeat/input/filestream.rotatedFilestreams.addRotatedFile
github.com/elastic/beats/v7/filebeat/input/filestream.(*copyTruncateFileProspector).onRotatedFile
github.com/elastic/beats/v7/filebeat/input/filestream.(*copyTruncateFileProspector).onFSEvent
github.com/elastic/beats/v7/filebeat/input/filestream.(*copyTruncateFileProspector).Run.func2
github.com/elastic/go-concert/unison.(*MultiErrGroup).Go.func1

This is an automatic backport of pull request #51570 done by [Mergify](https://mergify.com).

Fix filestream date sorter short path panic

Return a zero timestamp when a rotated file path is shorter than the configured
date format so copytruncate sorting cannot panic inside the prospector
goroutine.

(cherry picked from commit 09c13f0)
@mergify mergify Bot added the backport label Jun 29, 2026
@mergify
mergify Bot requested a review from a team as a code owner June 29, 2026 07:12
@mergify
mergify Bot requested review from belimawr and removed request for a team June 29, 2026 07:12
@mergify
mergify Bot requested a review from andrzej-stencel June 29, 2026 07:12
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@github-actions github-actions Bot added bug Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Jun 29, 2026
@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 29, 2026
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@mergify

mergify Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

This pull request has not been merged yet. Could you please review and merge it @orestisfl? 🙏

@orestisfl
orestisfl enabled auto-merge (squash) June 29, 2026 08:30
@orestisfl
orestisfl merged commit b354b80 into 8.19 Jun 29, 2026
46 of 49 checks passed
@orestisfl
orestisfl deleted the mergify/bp/8.19/pr-51570 branch June 29, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant