#15838·Redis

[BUG] HGETDEL that deletes nothing skips updateSlotAllocSize(), stranding the rehash shrink it caused (CLUSTER SLOT-STATS memory-bytes grows without bound)

Author: hanke580Created Sep 23, 2026Updated Sep 23, 2026

Describe the bug

hgetdelCommand() (src/t_hash.c) captures oldsize = kvobjAllocSize(o), looks every requested field up through addHashFieldToReply(), and then returns early when nothing was deleted or lazily expired:

c
    /* Return if no modification has been made. */
    if (vecSize(vexpired) == 0 && vecSize(vdeleted) == 0) {
        vecRelease(vexpired);
        vecRelease(vdeleted);
        return;                       /* skips updateSlotAllocSize() below */
    }
    ...
    /* update memory tracking */
    if (server.memory_tracking_enabled)
        updateSlotAllocSize(c->db, getKeySlot(c->argv[1]->ptr), o, oldsize, kvobjAllocSize(o));

"No modification" is true of the hash contents, not of its allocation. For a hashtable-encoded hash the lookups run incremental rehash steps; the step that completes the rehash frees the old table, so kvobjAllocSize(o) drops even though no field was touched. The early return skips the one call that would tell the slot, and the difference is stranded permanently, because dbGenericDelete() later subtracts the object's current (smaller) size.

Every other reader of the same hash re-syncs. Same 5-field hashtable hash, same starting state each time:

probe                        MEMORY USAGE   slot accumulator   residue after DEL
HGET f12                       513 -> 481       513 -> 481        0
HEXISTS f12                    513 -> 481       513 -> 481        0
HSTRLEN f12                    513 -> 481       513 -> 481        0
HRANDFIELD                     513 -> 481       513 -> 481        0
HGETEX ... FIELDS 1 f12        513 -> 481       513 -> 481        0
HGETDEL ... FIELDS 1 f12       513 -> 481       513 -> 513       32

To reproduce

Cluster-enabled node (--cluster-enabled yes --cluster-slot-stats-enabled yes, all slots assigned). Each round: HSET 200 fields of 150 bytes (forces hashtable, and the insert that crosses the load factor starts a rehash), 40 × HGETDEL key FIELDS 1 <missing field>, then DEL key. Afterwards the slot holds no keys (DBSIZE is 0), yet:

probe                                        rounds   CLUSTER SLOT-STATS memory-bytes
HGET zzN        (missing field)              20       0
HDEL zzN        (missing field)              20       0
HGETDEL zzN     (100 small fields, listpack) 20       0
HGETDEL zzN     (missing field)              1        1024
                                             2        2048
                                             5        5120
                                             20       20480

Exactly 1024 bytes — the freed 128-entry table — per round, linear, permanent.

With the built-in cross-check the server dies on the first occurrence (standalone is enough, since key-memory-histograms yes also sets memory_tracking_enabled):

redis-server --key-memory-histograms yes --enable-debug-command yes
redis> DEBUG ALLOCSIZE-SLOTS-ASSERT 1
redis> HSET h f00000 <150 bytes> ... f00199 <150 bytes>     # one HSET per field
redis> HGETDEL h FIELDS 1 zz0                                # repeat with zz1, zz2, ... until it dies
# Guru Meditation: dbgAssertAllocSizePerSlot: slot=0 expected=40924 actual=41948 #db.c:236

A self-checking Python reproducer (exit 1 when present, 0 when fixed; starts its own cluster-enabled redis-server) is attached / available on request. It requires the same loop through HGET, through HDEL, and on a listpack-encoded hash to all read 0, and the drift to be exactly linear in the number of rounds.

Expected behavior

CLUSTER SLOT-STATS memory-bytes should return to 0 when the slot is empty, as it does after the identical no-op through HGET or HDEL. Re-sync before the early return, since the lookups may have changed the allocation even when no field was removed:

c
     /* Return if no modification has been made. */
     if (vecSize(vexpired) == 0 && vecSize(vdeleted) == 0) {
+        if (server.memory_tracking_enabled)
+            updateSlotAllocSize(c->db, getKeySlot(c->argv[1]->ptr), o,
+                                oldsize, kvobjAllocSize(o));
         vecRelease(vexpired);
         vecRelease(vdeleted);
         return;
     }

Additional information

  • Reproduced on unstable @ c3215f01 (REDIS_VERSION 8.9.241, 2026-09-22) and on the released 8.10.2 (498ecd0d); both built from source with make MALLOC=jemalloc. On 8.10.2 the assertion reports #db.c:219.
  • Ubuntu 22.04.2, Linux 5.15.0-187-generic, gcc 11.4.0, x86_64.
  • On unstable: hgetdelCommand() starts at src/t_hash.c:5236, the early return is at :5304–5308, the skipped updateSlotAllocSize() at :5320.
  • Only reachable once the hash is past hash-max-listpack-value / hash-max-listpack-entries and mid-rehash; a listpack hash never shrinks on a lookup, which is why the early return reads as correct.
  • Open PR #15076 ("hash: pause auto-resize during HGETDEL") touches the same function but only defers resize work inside the delete loop; it does not add the missing accounting update on the no-op path.
  • Searched the tracker for hgetdel alloc, HGETDEL slot, updateSlotAllocSize, ALLOCSIZE-SLOTS-ASSERT, dbgAssertAllocSizePerSlot: the accounting fixes in #14746 (LTRIM/LREM, module string truncate) and #15037 (XINFO argv index) are the closest; nothing about HGETDEL.