Repository navigation
Description
Summary
The index read path bridges synchronous code to async storage through run_sync_on_runtime (fluree-db-binary-index/src/read/binary_index_store.rs). It is documented as safe on any Tokio runtime flavor. Two cases were found where it is not, both against remote (S3) storage. Neither affects the server, which runs multi-threaded and spawns the indexer worker with tokio::spawn.
First seen while adding an S3 + DynamoDB end-to-end test to #1862. Unrelated to that PR's change; the failing step runs before any collector pass is eligible.
1. Current-thread runtime: a CAS read times out instead of completing
Observed. On a #[tokio::test] (current-thread) runtime with S3Storage under LocalStack: create a ledger, insert, build an index through the background worker, then insert again. The second insert fails after exactly the configured S3 timeout:
Transact(FlakeGeneration("populate_dict_novelty_safe: I/O error: S3 timeout for key
'.../@shared/dicts/<hash>.dict': TimeoutError { kind: Operation, duration: 30s }"))
Reproducible on every run. The blob exists; the read never completes. The same scenario on a multi-thread runtime passes.
populate_dict_novelty_safe probes the persisted dictionaries synchronously, which reaches run_sync_on_runtime. On a current-thread runtime that takes the run_on_shared_cas_helper_thread branch: the calling thread parks in rx.recv() and the fetch runs on the process-wide fluree-cas-helper runtime.
Hypothesis, not yet confirmed. The fetch runs on the helper runtime but through the same aws_sdk_s3::Client the outer runtime has already used. Hyper's pooled connections are driven by tasks spawned on the runtime that opened them. A fetch that checks out a connection opened on the outer runtime is waiting on a driver task that lives on the one thread now parked in recv(). The SDK's operation timeout, running on the helper runtime's timer, is what eventually fires. This fits the evidence (an Operation timeout rather than a hang or a 404, and only once the client has pooled connections from earlier outer-runtime use) but has not been isolated.
Suggested investigation. A two-case test on a current-thread runtime against LocalStack:
- client first used from the outer runtime, then a read through the bridge (expected: times out);
- a fresh client used only through the bridge (expected: completes).
If that confirms it, candidate fixes are a dedicated S3 client for bridged reads, or ensuring bridged reads never reuse a connection opened on another runtime.
Who it affects. An embedded user on a current-thread runtime against remote storage, transacting after an index exists. The bridge's doc comment promises this case works.
2. Multi-thread runtime inside a LocalSet: block_in_place panics
Observed. Same scenario with #[tokio::test(flavor = "multi_thread")] and the worker on a LocalSet (support::start_background_indexer_local, body inside local.run_until):
panicked at fluree-db-binary-index/src/read/leaflet_cache.rs:483:59:
can call blocking only when running on the multi-threaded runtime
in_blocking_region (leaflet_cache.rs) and run_sync_on_runtime both choose block_in_place from runtime_flavor() == MultiThread alone. block_in_place also panics from a task running on a LocalSet, whatever the flavor. This one is confirmed: it is a documented Tokio restriction and the panic is deterministic.
Who it affects. Tests, today: start_background_indexer_local cannot be combined with remote storage once a transaction follows a build. Any embedder that drives Fluree from a LocalSet would hit the same panic.
Candidate fix. Detect the LocalSet case and fall back to the helper-thread path, in both functions. Whether Tokio exposes a reliable check needs looking at; catching the restriction up front is preferable to catch_unwind.
Workaround in the tree
The S3 end-to-end test added in #1862 (s3_testcontainers_collector_and_fork_drop_keep_every_referenced_dictionary) uses a multi-thread runtime and tokio::spawn(worker.run()), as the server does, with a comment saying why. Once this is fixed that test could go back to the shared LocalSet helper.
Not covered by CI
The LocalStack suites (--features aws-testcontainers) have no CI job, so nothing would have caught either case.
Activity