Skip to content

Commit 1fe20da

Browse files
authored
fix(stream): prevent assert failure in XDEL with non-existent ID (#5918)
Fixed: #5202
1 parent 37b217a commit 1fe20da

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/server/stream_family.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,11 @@ OpResult<uint32_t> OpDel(const OpArgs& op_args, string_view key, absl::Span<stre
15961596
} else if (first_entry) {
15971597
streamGetEdgeID(stream_inst, 1, 1, &stream_inst->first_id);
15981598
}
1599+
// Only update size tracking if we actually deleted something.
1600+
// This avoids issues with memory tracking noise from other operations
1601+
// in the same thread.
1602+
tracker.UpdateStreamSize(cobj);
15991603
}
1600-
1601-
tracker.UpdateStreamSize(cobj);
16021604
return deleted;
16031605
}
16041606

src/server/stream_family_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,4 +1311,13 @@ TEST_F(StreamFamilyTest, XClaimWithNonExistentGroup) {
13111311
EXPECT_THAT(resp, ArrLen(0));
13121312
}
13131313

1314+
TEST_F(StreamFamilyTest, XDelNonExistentId) {
1315+
string key = R"(k1 "v1" k2 "v2 with spaces" "k3 with spaces" "v3")";
1316+
Run({"XADD", key, "0", "set1", "member1"});
1317+
1318+
// Try to delete a non-existent ID - should not crash (issue #5202)
1319+
auto resp = Run({"XDEL", key, "46-867"});
1320+
EXPECT_THAT(resp, IntArg(0)); // Nothing deleted
1321+
}
1322+
13141323
} // namespace dfly

0 commit comments

Comments
 (0)