From fb7b94545366926f6cb2f09dcda51365e301eda9 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 5 Sep 2021 00:47:14 +0200 Subject: [PATCH] Fix a crash on --existing and --regex together. --regex (and other linear scans) would launch multiple threads, but IOUringEngine isn't thread-safe. Since --existing is obscure, and --regex is obscure, we solve this by simply making synchronous stat() calls. Reported by Michael Arndt. --- plocate.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plocate.cpp b/plocate.cpp index 44a1375..d021cc8 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -348,7 +348,7 @@ uint64_t scan_all_docids(const vector &needles, int fd, const Corpus &co dprintf("Using %u worker threads for linear scan.\n", num_threads); unique_ptr threads(new WorkerThread[num_threads]); for (unsigned i = 0; i < num_threads; ++i) { - threads[i].t = thread([&threads, &mu, &queue_added, &queue_removed, &work_queue, &done, &offsets, &needles, &access_rx_cache, engine{ corpus.engine }, &matched, i] { + threads[i].t = thread([&threads, &mu, &queue_added, &queue_removed, &work_queue, &done, &offsets, &needles, &access_rx_cache, &matched, i] { // regcomp() takes a lock on the regex, so each thread will need its own. const vector *use_needles = &needles; vector recompiled_needles; @@ -379,7 +379,8 @@ uint64_t scan_all_docids(const vector &needles, int fd, const Corpus &co for (uint32_t docid = io_docid; docid < last_docid; ++docid) { size_t relative_offset = offsets[docid] - offsets[io_docid]; size_t len = offsets[docid + 1] - offsets[docid]; - scan_file_block(*use_needles, { &compressed[relative_offset], len }, engine, &access_rx_cache, docid, &receiver, &matched); + // IOUringEngine isn't thread-safe, so we do any needed stat()s synchronously (nullptr engine). + scan_file_block(*use_needles, { &compressed[relative_offset], len }, /*engine=*/nullptr, &access_rx_cache, docid, &receiver, &matched); } } }); -- 2.39.2