diff --git a/src/dict.c b/src/dict.c index 6e9b13150bfb..d04f9e1231a9 100644 --- a/src/dict.c +++ b/src/dict.c @@ -706,6 +706,10 @@ int _dictClear(dict *d, int htidx, void(callback)(dict*)) { /* Clear & Release the hash table */ void dictRelease(dict *d) { + /* Someone may be monitoring a dict that started rehashing, before + * destroying the dict fake completion. */ + if (dictIsRehashing(d) && d->type->rehashingCompleted) + d->type->rehashingCompleted(d); _dictClear(d,0,NULL); _dictClear(d,1,NULL); zfree(d); @@ -1588,6 +1592,10 @@ void *dictFindPositionForInsert(dict *d, const void *key, dictEntry **existing) } void dictEmpty(dict *d, void(callback)(dict*)) { + /* Someone may be monitoring a dict that started rehashing, before + * destroying the dict fake completion. */ + if (dictIsRehashing(d) && d->type->rehashingCompleted) + d->type->rehashingCompleted(d); _dictClear(d,0,callback); _dictClear(d,1,callback); d->rehashidx = -1; diff --git a/src/kvstore.c b/src/kvstore.c index 505f92957fac..62b799dddc16 100644 --- a/src/kvstore.c +++ b/src/kvstore.c @@ -957,6 +957,9 @@ int kvstoreTest(int argc, char **argv, int flags) { } kvstoreIteratorRelease(kvs_it); + /* Make sure the dict was removed from the rehashing list. */ + while (kvstoreIncrementallyRehash(kvs2, 1000)) {} + dict *d = kvstoreGetDict(kvs2, didx); assert(d == NULL); assert(kvstoreDictSize(kvs2, didx) == 0);