···520520 trace!(elapsed = %start.elapsed().as_secs_f32(), "parsed car");
521521522522 let start = Instant::now();
523523+ let root_cid = parsed.root;
523524 let store = Arc::new(MemoryBlockStore::new_from_blocks(parsed.blocks));
525525+ // parsed.blocks was moved into the store; parsed.root is now root_cid. drop the raw
526526+ // CAR bytes here so we don't hold two copies of the block data (raw + parsed) for
527527+ // the entire duration of the spawn_blocking call below.
528528+ drop(car_bytes);
524529 trace!(
525530 blocks = store.len(),
526531 elapsed = ?start.elapsed(),
···529534530535 // 4. parse root commit to get mst root
531536 let root_bytes = store
532532- .get(&parsed.root)
537537+ .get(&root_cid)
533538 .await
534539 .into_diagnostic()?
535540 .ok_or_else(|| miette::miette!("root block missing from CAR"))?;
···575580 let mut added_blocks = 0;
576581 let mut collection_counts: HashMap<SmolStr, u64> = HashMap::new();
577582 let mut batch = app_state.db.inner.batch();
578578- let store = mst.storage();
583583+ // clone the Arc so we hold an independent reference to the block store,
584584+ // allowing mst (and its entire loaded node tree) to be freed immediately
585585+ // rather than surviving until the end of spawn_blocking.
586586+ let store = mst.storage().clone();
587587+ drop(mst);
579588580589 let prefix = keys::record_prefix_did(&did);
581590 let mut existing_cids: HashMap<(SmolStr, DbRkey), SmolStr> = HashMap::new();
···698707 count += 1;
699708 }
700709 }
710710+711711+ // all blocks have been read; free the MemoryBlockStore now so it does not
712712+ // survive through the final batch commit or any fjall backpressure stall.
713713+ drop(store);
701714702715 // remove any remaining existing records (they weren't in the new MST)
703716 for ((collection, rkey), cid) in existing_cids {
+1-1
src/control/mod.rs
···126126 pub fn resolver(&self) -> &crate::resolver::Resolver {
127127 &self.state.resolver
128128 }
129129-129129+130130 /// open the database and configure hydrant from `config`.
131131 ///
132132 /// this sets up the database, applies any filter configuration from `config`, and