]> git.sesse.net Git - plocate/commitdiff
Fix a crash on --existing and --regex together.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 4 Sep 2021 22:47:14 +0000 (00:47 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 4 Sep 2021 22:47:14 +0000 (00:47 +0200)
--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

index 44a1375ad53097778b3aa4a104155ed6bb529876..d021cc89d6281bf90a74cc56a005dd83b29b293c 100644 (file)
@@ -348,7 +348,7 @@ uint64_t scan_all_docids(const vector<Needle> &needles, int fd, const Corpus &co
        dprintf("Using %u worker threads for linear scan.\n", num_threads);
        unique_ptr<WorkerThread[]> 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<Needle> *use_needles = &needles;
                        vector<Needle> recompiled_needles;
@@ -379,7 +379,8 @@ uint64_t scan_all_docids(const vector<Needle> &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);
                                }
                        }
                });