From 8d8aabb978500fd590b1addfcd9de7118eed06b2 Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 17 May 2022 02:59:32 +0000 Subject: [PATCH] Prevent us from starting a rehash when one wasn't already in progress. This can cause severe issues for snapshots --- src/dict.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dict.cpp b/src/dict.cpp index ffccb545c..9a15830ae 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -468,13 +468,18 @@ bool dictRehashSomeAsync(dictAsyncRehashCtl *ctl, size_t hashes) { void discontinueAsyncRehash(dict *d) { + // We inform our async rehashers and the completion function the results are to be + // abandoned. We keep the asyncdata linked in so that dictEntry's are still added + // to the GC list. This is because we can't gurantee when the other threads will + // stop looking at them. if (d->asyncdata != nullptr) { auto adata = d->asyncdata; - while (adata != nullptr) { + while (adata != nullptr && !adata->abondon.load(std::memory_order_relaxed)) { adata->abondon = true; adata = adata->next; } - d->rehashidx = 0; + if (dictIsRehashing(d)) + d->rehashidx = 0; } }