← Back to Pull requests

fix(buffers): flush partial sink batches during disk-buffer shutdown #27260

Closed
unknown closed this pull request without merging on Nov 30, 2026 20:13 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 21:32 UTC
Author

Summary

This replaces #26969, which I have now closed. GitHub permission issues prevented me from posting comments on the old PR. Please continue review here. This PR carries forward the latest branch, including the merges from master through d6da0c7bb0.

With disk buffering, a partial sink batch can wait for batch.timeout_secs during shutdown: the disk reader waits for acknowledgements before returning EOF, while the batcher needs EOF to flush the records that will produce those acknowledgements. A long batch timeout can therefore exhaust the shutdown grace period even when the destination is healthy.

Separate input exhaustion from acknowledgement completion. Retain the receiver after natural EOF so sinks can flush their final batches, then process outstanding acknowledgements and persist the reader checkpoint before the sink task completes. Reload-detached receivers remain available for reuse. The shutdown reporter also defers success to the aggregate task result so a checkpoint failure cannot be masked by a completed task.

Add regression coverage for partial partitions, pending finalizers and shutdown deadlines, final-write/rollover races, replay, checkpoint failures, and memory/disk receiver reuse. Update the buffer property model and direct buffer consumers for the two-phase lifecycle.

References

Closes #25774.

Related reports and history:

  • #19600 (closed): earlier report of disk-buffered sinks waiting for the batch timeout during shutdown. The continuing S3 problem was filed as #25774 at a maintainer's request.

  • #11405 (closed): earlier sink-flushing discussion, including subsequent reports of S3 shutdown timeouts with disk buffers.

  • #24948 (closed): disk-buffered sinks stalled during configuration reload until the batch timeout elapsed; relevant context for preserving receiver reuse during reload.

  • #18133 (open): broader request to flush sink batches immediately during configuration reload.
  • The reload issues are linked as related context. This PR's shutdown regression tests cover natural input EOF; the broader reload behavior needs separate validation.

    Vector configuration

    The topology tests construct their configuration in Rust: a test source feeds a disk-buffered test sink using the production PartitionedBatcher, with two partial partitions, a five-minute batch timeout, and a two-second shutdown limit. No configuration fields or on-disk formats change.

    For the real-process smoke test, used stdin → disk buffer → HTTP sink with a loopback HTTP receiver returning HTTP 200. Temporary paths and the receiver port are normalized below:

    data_dir: /tmp/vector-shutdown-smoke
    sources:
      input:
        type: stdin
        decoding:
          codec: json
    sinks:
      output:
        type: http
        inputs: [input]
        uri: 'http://127.0.0.1:9000/{{ partition }}'
        method: post
        healthcheck:
          enabled: false
        framing:
          method: newline_delimited
        encoding:
          codec: json
        buffer:
          type: disk
          max_size: 268435488
          when_full: block
        batch:
          max_events: 100
          timeout_secs: 300
    

    The process was started with --graceful-shutdown-limit-secs 30.

    How did you test this PR?

    The results below are carried forward from #26969. The recorded local build and smoke tests were run at 7a2c82d703, before the later merges from master. Tests have not been rerun for this PR recreation.

    On macOS arm64 with the pinned Rust 1.96.1 toolchain:

  • Buffer unit suite: 122 passed, 1 existing ignored.

  • Topology suite, including reload tests, run serially: 67 passed, 1 existing ignored.

  • make check-clippy with the feature set below: passed.

  • make fmt, make check-fmt, make check-markdown, and make check-changelog-fragments: passed.
  • cargo test --quiet -p vector-buffers --lib
    cargo test --quiet -p vector --lib --no-default-features \
      --features 'sources-prometheus sinks-prometheus sources-internal_metrics sources-splunk_hec enrichment-tables-memory' \
      topology:: -- --test-threads=1
    FEATURES='sources-prometheus sinks-prometheus sources-internal_metrics sources-splunk_hec enrichment-tables-memory' make check-clippy
    

    Confirmed the batching regression reaches the shutdown deadline with the original v0.61.0 buffer lifecycle code restored, and the reporter regression detects the original false-success behavior. Both pass with the fix.

    The parallel topology run failed in the existing topology_reload_preserves_enrichment_table_state test; that test passed in isolation and in the full serial suite.

    Real-process shutdown and delivery verification

    Reproduction scripts, YAML configuration, results for all seven checks, captured HTTP requests, and shutdown logs are available in the smoke-test gist.

    Built and tested commit 7a2c82d703 on macOS arm64 using the debug binary (vector 0.62.0-dev-custom-7a2c82d703). Built via cargo vdev run, which selected only sources-stdin and sinks-http for the configuration above. These smoke checks ran after the merge from master.

    With a 30-second shutdown grace period and a 300-second batch timeout:

  • Submitted 80 uniquely identified JSON events, alternating between partitions a and b. Each event included a message and a nested payload with a sequence number, boolean, Unicode text, and an array.

  • Waited for disk-reader logs to confirm all 80 events had been read, kept stdin open, and confirmed no HTTP requests had been emitted before sending SIGTERM. Both 40-event batches remained below the 100-event limit.

  • After SIGTERM, the receiver captured two HTTP requests containing 40 events each. Compared captured events against the submitted input: 80 received, 80 unique, zero missing, duplicate, or unexpected events. Verified all original fields, routing to /a or /b, and event order within each partition.

  • Vector exited successfully and logged graceful shutdown in 37 ms, with no error logs. Restarting with the same disk buffer and no new input emitted zero events, confirming no replay in this case.
  • Additional real-process checks with a two-second grace period verified that Vector waited for HTTP responses delayed by 300 ms, reached the shutdown deadline when responses were withheld, and replayed all four unacknowledged events on restart. The deadline check used logs because the process currently returns exit code 0 even when the shutdown grace period expires.

    These are functional checks against a local HTTP receiver; throughput has not been benchmarked. Live S3 verification has not been run.

    Does this PR include user facing changes?

  • Yes. Added changelog.d/25774_disk_buffer_shutdown.fix.md.

  • No.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: pront Review duration: 17200m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #27260"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%