valeriansaliou/sonic · critical · panic

write_buffer for kv must not be zero

Error message

write_buffer for kv must not be zero

What it means

Sonic's Config::validate() panics if the KV store's write_buffer_size is explicitly set to Some(0). A zero-sized write buffer means the KV engine could never buffer writes before flushing, which is an invalid configuration. The panic happens at startup, before the server accepts traffic.

Source

Thrown at core/src/config.rs:38

#[derive(Deserialize)]
pub struct Config {
    pub normalization: ConfigNormalization,

    pub tokenization: ConfigTokenization,

    pub stopwords: ConfigStopwords,

    pub search: ConfigSearch,

    pub store: ConfigStore,
}

impl Config {
    pub fn validate(&self) {
        // Check 'write_buffer' for KV
        if self.store.kv.database.write_buffer_size == Some(0) {
            panic!("write_buffer for kv must not be zero");
        }

        // Check 'flush_after' for KV
        if self.store.kv.database.flush_after >= self.store.kv.pool.inactive_after {
            panic!("flush_after for kv must be strictly lower than inactive_after");
        }

        // Check 'flush_after' for KV
        if self.store.kv.database.max_flushes.is_some()
            && self.store.kv.database.max_background_jobs.is_some()
        {
            panic!("max_background_jobs makes max_flushes unneeded, don’t configure both");
        }

        // Check 'consolidate_after' for FST
        if self.store.fst.graph.consolidate_after >= self.store.fst.pool.inactive_after {
            panic!("consolidate_after for fst must be strictly lower than inactive_after");
        }

View on GitHub (pinned to e6a72da6a5)

Solutions

  1. Remove the write_buffer_size key from the [store.kv.database] section to use the default
  2. Set write_buffer_size to a positive value (e.g. 1024)
  3. Restart the server after fixing the config

Example fix

// config.toml
// before
[store.kv.database]
write_buffer_size = 0

// after
[store.kv.database]
write_buffer_size = 1024
Defensive patterns

Strategy: validation

Validate before calling

// before starting the server
let cfg = config_from_toml(&raw);
if cfg.store.kv.database.write_buffer_size == Some(0) {
    return Err("store.kv.database.write_buffer_size must be > 0 or omitted".into());
}

Prevention

When it happens

Trigger: Setting store.kv.database.write_buffer_size = 0 in the TOML config file and starting the server (Config::validate runs during boot).

Common situations: Hand-edited TOML configs where a user 'disables' buffering by setting 0; templated configs filling an option with 0; misunderstanding that the Option means 'unset', so 0 must simply be omitted.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of valeriansaliou/sonic@e6a72da6a5 (2026-09-01). Data as JSON: /api/errors/4de5672e04a044a2. Report an issue: GitHub.