Stream settings PUT succeeds but leaves in-memory cache stale, causing intermittent read-after-write inconsistency (e.g. enable_distinct_fields)
Summary
PUT /api/{org}/streams/{name}/settings can succeed (200) while leaving the in-memory settings cache stale, so an immediate follow-up GET /api/{org}/streams/{name}/schema intermittently returns the previous settings instead of the ones just written. Any client that does a write-then-read-back cycle (like the terraform-provider-openobserve openobserve_stream resource, which reads back after every create/update to populate Terraform state) will intermittently see:
Error: Provider produced inconsistent result after apply
.enable_distinct_fields: was cty.True, but now cty.False.(Same shape applies to any other settings field, not just enable_distinct_fields — that's just the one we hit.)
Root cause
- The settings write path (
PUT .../settings→stream::update_stream_settings→schema::save_stream_settings→persist_stream_settings,src/schema/src/lib.rs:220-388) writes the new settings only to the database, viadb::schema::update_setting()at line 380. It never callsinfra::schema::put_stream_settings()to update the in-memory cache. - The read path (
GET .../schema→infra::schema::get_settings,src/infra/src/schema/mod.rs:298-328) checks the lock-freeSTREAM_SETTINGS_ATOMICsnapshot first (line 306) and only falls back to the DB if that snapshot has no entry for the stream. If an entry already exists (e.g. from an earlier read of the same stream, or from ingestion having previously touched it), the read never reaches the DB at all and returns whatever is cached — which the write path never invalidated. - The DB write in
update_setting()does usedb.get_for_update(..., NEED_WATCH, ...)(src/infra/src/schema/mod.rs:680-682), which fires a watch event. The only place that event actually refreshesSTREAM_SETTINGS_ATOMICis the schema watcher's event handler (src/schema/src/watcher.rs:161) — but that handler runs asynchronously on whatever schedule the watch-event channel delivers it, with no ordering guarantee relative to the HTTP handler's own immediate follow-up read.
So this is a genuine TOCTOU race, not a timing coincidence: whether a caller sees the stale value depends entirely on whether the watcher's background task has processed the write's watch event before the caller's own next GET runs. Under any concurrent load (many streams being created/updated close together — e.g. Terraform's default -parallelism=10) the watcher queue backs up and the race becomes easy to hit; on a quiet server doing one write at a time it's much less likely to.
Reproduction
Confirmed on OpenObserve Enterprise v1.0.4 (public.ecr.aws/zinclabs/openobserve-enterprise:v1.0.4, self-reported version confirmed via GET /api/_meta/node/list) with terraform-provider-openobserve v1.3.1, applying ~90 openobserve_stream resources (mixed create/update) in one terraform apply. Example from a real run:
Error: Provider produced inconsistent result after apply
When applying changes to
module.***.***.this, provider
"provider[\"registry.terraform.io/openobserve/openobserve\"]" produced an
unexpected new value: .enable_distinct_fields: was cty.True, but now
cty.False.A minimal, single-request repro (POST create → PUT settings enable_distinct_fields=true → immediate GET, no concurrency) does not reliably trigger it on an idle server — consistent with the root cause above requiring the watcher to be behind, which is far more likely under real concurrent load than in an isolated single-stream test.
Suggested fix
persist_stream_settings() should update STREAM_SETTINGS/STREAM_SETTINGS_ATOMIC synchronously as part of the same write (the way handle_diff_schema()'s ingestion path already does at src/schema/src/lib.rs:812), rather than relying exclusively on the async watcher to eventually catch up. Alternatively/additionally, get_settings() could invalidate or bypass the atomic snapshot for some short window after a local write, though the synchronous-cache-update fix seems more directly correct and is already the pattern used elsewhere in the same file.
Environment
- OpenObserve Enterprise
v1.0.4(confirmed viaGET /api/_meta/node/listself-reported version) terraform-provider-openobservev1.3.1- Local Docker Compose, single node,
ZO_LOCAL_MODE=true
Source: openobserve/openobserve