vectordotdev/vector · error

double chunk_size_events initialization

Error message

double chunk_size_events initialization

What it means

The source-sender chunk size is a process-wide setting stored in a static AtomicUsize. set_chunk_size_events() installs it with compare_exchange(0, size): the first call flips the global from 0 to the configured value; any later call finds a non-zero current value and panics with 'double chunk_size_events initialization'. The setting must be applied exactly once, before the topology is built, because SourceSender buffers are sized from it (threads * chunk_size_events).

Source

Thrown at lib/vector-core/src/source_sender/mod.rs:43

static CHUNK_SIZE_EVENTS: AtomicUsize = AtomicUsize::new(0);

/// Returns the configured source sender chunk size in events, or [`DEFAULT_CHUNK_SIZE_EVENTS`] if
/// unset.
#[must_use]
pub fn chunk_size_events() -> usize {
    match CHUNK_SIZE_EVENTS.load(Ordering::Relaxed) {
        0 => DEFAULT_CHUNK_SIZE_EVENTS,
        size => size,
    }
}

/// Sets the process-wide source sender chunk size in events. Must be called at most once, before
/// the topology is built. Panics if called more than once.
pub fn set_chunk_size_events(size: usize) {
    CHUNK_SIZE_EVENTS
        .compare_exchange(0, size, Ordering::Acquire, Ordering::Relaxed)
        .unwrap_or_else(|_| panic!("double chunk_size_events initialization"));
}

#[cfg(any(test, feature = "test"))]
const TEST_BUFFER_SIZE: usize = 100;

use vector_common::internal_event::HistogramName;

const LAG_TIME_NAME: HistogramName = HistogramName::SourceLagTimeSeconds;
const SEND_LATENCY_NAME: HistogramName = HistogramName::SourceSendLatencySeconds;
const SEND_BATCH_LATENCY_NAME: HistogramName = HistogramName::SourceSendBatchLatencySeconds;

/// A post-processing step applied to every event that flows through a [`SourceSender`].
///
/// Implement this trait to mutate events just before they are placed on the output channel.
/// Because each method receives a typed reference, it is impossible at the type level to
/// accidentally change an event's variant.
///
/// It is applied *globally* — to all outputs (default and named ports) produced by the same

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Call set_chunk_size_events exactly once at process start, before any topology is built
  2. In test suites, set it in a shared once-per-process hook (or not at all, relying on DEFAULT_CHUNK_SIZE_EVENTS) instead of per-test
  3. Use a std::sync::Once / OnceLock guard around the call so accidental double invocation is a no-op rather than a panic

Example fix

// before
set_chunk_size_events(size); // second call panics

// after
static INIT: std::sync::Once = std::sync::Once::new();
INIT.call_once(|| set_chunk_size_events(size));
Defensive patterns

Strategy: validation

Validate before calling

static CHUNK_INIT: std::sync::Once = std::sync::Once::new();
CHUNK_INIT.call_once(|| set_chunk_size_events(size)); // idempotent across calls

Prevention

When it happens

Trigger: Calling set_chunk_size_events twice in one process - e.g. multiple test binaries/cases sharing a process, or embedding code building two topologies with different chunk sizes. In the Vector CLI it is set once from the --chunk-size-events flag in app.rs, so end users normally cannot trigger it.

Common situations: Integration test suites where each test calls set_chunk_size_events in setup; library consumers that build/teardown pipelines in a loop; passing --chunk-size-events while a wrapper already initialized it.

Related errors


AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/22da04737ebded7e. Report an issue: GitHub.