Skip to content

fix(traces): avoid panic on empty /v0.6/stats payload#1290

Open
lucaspimentel wants to merge 2 commits into
mainfrom
lpimentel/fix-stats-processor-empty-payload-panic
Open

fix(traces): avoid panic on empty /v0.6/stats payload#1290
lucaspimentel wants to merge 2 commits into
mainfrom
lpimentel/fix-stats-processor-empty-payload-panic

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Jul 1, 2026

Copy link
Copy Markdown
Member

Overview

The /v0.6/stats handler unconditionally indexed stats.stats[0] to stamp the payload start time. When the request body is an empty msgpack map (0x80), stats_utils::get_stats_from_request_body returns a ClientStatsPayload with an empty stats vec, so stats.stats[0] panicked:

index out of bounds: the len is 0 but the index is 0

This is a pre-existing bug reproducible in the Lambda binary; it surfaced while smoke-testing the test-mode binary.

The fix guards the empty case before indexing: an empty payload has nothing to buffer, so we return 202 Accepted as a harmless no-op. When at least one bucket exists, we set .start via stats.first_mut().

Testing

Added a regression test (empty_stats_payload_does_not_panic) that feeds an empty msgpack map body and asserts the handler returns 202 Accepted without panicking and buffers nothing to the aggregator.

🤖

An empty msgpack map request body deserializes to a stats payload with
no buckets, so indexing stats[0] to stamp the start time panicked with
"index out of bounds". Guard the empty case and return 202 Accepted as a
no-op instead. Adds a regression test.

🤖
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 1, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 2 Pipeline jobs failed

DataDog/datadog-lambda-extension | bottlecap (amd64, fips)   View in Datadog   GitLab

DataDog/datadog-lambda-extension | layer (arm64)   View in Datadog   GitLab

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3a1a38d | Docs | Datadog PR Page | Give us feedback!

@lucaspimentel lucaspimentel changed the title fix(traces): avoid panic on empty /v0.6/stats payload fix(traces): avoid panic on empty /v0.6/stats payload Jul 1, 2026
@lucaspimentel lucaspimentel marked this pull request as ready for review July 2, 2026 14:19
@lucaspimentel lucaspimentel requested review from a team as code owners July 2, 2026 14:19
@lucaspimentel lucaspimentel requested review from Copilot and lym953 and removed request for Copilot July 2, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in the trace stats ingestion path (/v0.6/stats) by handling the edge case where the decoded ClientStatsPayload contains zero stats buckets, preventing an out-of-bounds panic in the Lambda extension’s traces subsystem.

Changes:

  • Guard against empty stats.stats and treat empty payloads as a harmless no-op returning 202 Accepted.
  • Replace direct indexing (stats.stats[0]) with first_mut() to safely access the first bucket when present.
  • Add a regression test ensuring an empty msgpack map body does not panic and does not enqueue anything to the aggregator channel.

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.

2 participants