From 0a21d9bfb3f4f0bb83982f12ce1349f86d2ff501 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 18 Nov 2024 15:56:01 +0100 Subject: [PATCH] Fix double borrow of new fields id map --- crates/milli/src/update/new/extract/documents.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/milli/src/update/new/extract/documents.rs b/crates/milli/src/update/new/extract/documents.rs index a324d2914..c0a2e3d6a 100644 --- a/crates/milli/src/update/new/extract/documents.rs +++ b/crates/milli/src/update/new/extract/documents.rs @@ -43,10 +43,12 @@ impl<'a, 'extractor> Extractor<'extractor> for DocumentsExtractor<'a> { let mut document_buffer = bumpalo::collections::Vec::new_in(&context.doc_alloc); let mut document_extractor_data = context.data.0.borrow_mut_or_yield(); - let mut new_fields_ids_map = context.new_fields_ids_map.borrow_mut_or_yield(); - for change in changes { let change = change?; + // **WARNING**: the exclusive borrow on `new_fields_ids_map` needs to be taken **inside** of the `for change in changes` loop + // Otherwise, `BorrowMutError` will occur for document changes that also need the new_fields_ids_map (e.g.: UpdateByFunction) + let mut new_fields_ids_map = context.new_fields_ids_map.borrow_mut_or_yield(); + let external_docid = change.external_docid().to_owned(); // document but we need to create a function that collects and compresses documents.