cockroachdb / cockroachdb/cockroach

backup: TrailingMetaCallback in restoreDataProcessor uses stale context for tracing metadata

Open
#166,623 1 comment 0 reactions 0 assignees View on GitHub
branch-master C-bug O-agent T-testeng
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

## Summary

The `TrailingMetaCallback` registered by `newRestoreDataProcessor` captures the constructor's `ctx` parameter in its closure and passes it to `ConstructTracingAggregatorProducerMeta`. This context does not carry the processor's tracing span, which is created later during `StartInternal`. As a result, the span totals emitted in trailing metadata may reference the wrong span hierarchy, leading to inaccurate trace statistics.

## Severity

Low. This affects observability/diagnostics only, not data correctness or restore reliability.

## Evidence

- `pkg/backup/restore_data_processor.go:133-167` — closure captures constructor `ctx`
- `pkg/backup/restore_data_processor.go:157` — passes stale `ctx` to `ConstructTracingAggregatorProducerMeta`
- `pkg/backup/restore_data_processor.go:913` — `Next()` correctly uses `rd.Ctx()` for comparison

## Additional Findings

1. **Dead code:** `openSSTs` method is only called from tests, not production. Production uses `openSSTsForFiles`.
2. **Panic recovery reformatting:** `cancelWorkersAndWait` catches structured `verboseError` panics and re-panics with `fmt.Sprintf(...)`, losing structured error info.

## Suggested Fix

Extract tracing metadata *before* calling `ConsumerClosed()` so the processor's span is still active.

_This issue was found via automated deep static analysis._

Jira issue: CRDB-62035

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.