Solution (#4143): [BUG] Tracking table items not cleaned after client disconnect#4163
Solution (#4143): [BUG] Tracking table items not cleaned after client disconnect#4163TFGSUMIT wants to merge 1 commit into
Conversation
…fter client disconne
📝 WalkthroughWalkthroughAdds ChangesTracking table interface
Estimated code review effort: 1 (Trivial) | ~2 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@c`:
- Around line 4-12: Update struct tracking_table to use the correct jemalloc
arena type: forward-declare struct arena_s, replace its arena member with struct
arena_s *arena, and remove the unnecessary arena_structs.h include.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| #include "deps/jemalloc/include/jemalloc/internal/arena_structs.h" | ||
|
|
||
| struct tracking_table { | ||
| struct arena *arena; | ||
| }; | ||
|
|
||
| void tracking_table_defragment(struct tracking_table *table); | ||
| void tracking_table_sweep_dead_clients(struct tracking_table *table); | ||
| void tracking_table_periodic_sweep(struct tracking_table *table); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n '\b(struct arena|struct arena_s|arena_t|tracking_table)\b' .Repository: valkey-io/valkey
Length of output: 25920
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== file c =="
cat -n c
echo
echo "== jemalloc arena typedefs =="
sed -n '1,80p' deps/jemalloc/include/jemalloc/internal/arena_types.h
echo
echo "== jemalloc arena structs =="
sed -n '1,80p' deps/jemalloc/include/jemalloc/internal/arena_structs.hRepository: valkey-io/valkey
Length of output: 4922
Use struct arena_s * for the tracking-table arena pointer.
struct arena * is a different incomplete type from jemalloc’s struct arena_s/arena_t, so this won’t match real arena pointers. Forward-declare struct arena_s here and store struct arena_s *arena; instead of including the internal arena definition.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@c` around lines 4 - 12, Update struct tracking_table to use the correct
jemalloc arena type: forward-declare struct arena_s, replace its arena member
with struct arena_s *arena, and remove the unnecessary arena_structs.h include.
Source: MCP tools
There was a problem hiding this comment.
This diff does not fix #4163's referenced issue, or change server behavior at all. It adds a single file literally named c at the repository root; nothing in the tree includes it, src/Makefile/CMakeLists.txt never compile it, and the three declared functions have no definitions or callers anywhere (grep finds them only in this file). The PR description also doesn't match the diff: it claims modifications to tracking.c, new max_rax_size/num_dead_clients fields, and a ./run_test.sh test script — none are in the diff, and run_test.sh does not exist in the repository (git diff --stat shows only c | 14 +). A real fix for #4143 needs to operate on the actual tracking table — rax *TrackingTable in src/tracking.c (src/tracking.c:44), where the lazy client-ID cleanup logic lives — and come with a Tcl test under tests/.
|
|
||
| #include "deps/jemalloc/include/jemalloc/internal/arena_structs.h" | ||
|
|
||
| struct tracking_table { |
There was a problem hiding this comment.
This header is dead code: no file includes it, src/Makefile and src/CMakeLists.txt never reference it, and tracking_table_defragment/tracking_table_sweep_dead_clients/tracking_table_periodic_sweep are declared here but defined and called nowhere in the tree. struct tracking_table is likewise unused — the server's tracking table is rax *TrackingTable in src/tracking.c:44, which this PR never touches. The file is also misnamed: it landed as a file literally called c at the repository root instead of a header under src/. As-is the change is a no-op with respect to the reported bug; the sweeper needs an implementation in src/tracking.c wired into the disconnect/cron path.
| #ifndef TRACKING_H | ||
| #define TRACKING_H | ||
|
|
||
| #include "deps/jemalloc/include/jemalloc/internal/arena_structs.h" |
There was a problem hiding this comment.
This pulls in a jemalloc internal header. jemalloc's struct arena_s is a memory-allocator arena and has no relation to the client tracking table. It is also not includable from server code: the path is relative to the repo root (server sources build from src/ without a repo-root include path), the header chains into a dozen other jemalloc/internal/* headers that require jemalloc's configure-generated definitions (jemalloc_internal_defs.h does not exist until the dep is built), and Valkey supports MALLOC=libc builds where jemalloc isn't configured at all. Any state the tracking cleanup needs belongs in src/tracking.c's own structures, not in deps/.
"PR: Fix tracking table items not being cleaned after client disconnect
This PR addresses the issue of tracking table items not being cleaned after a client disconnect by introducing a periodic sweeper to clean up dead client IDs.
Changes:
arenastruct to include fieldsmax_rax_sizeandnum_dead_clientsto track the maximum size of the inner RAX and the number of dead client IDs, respectively.tracking_table_defragment,tracking_table_sweep_dead_clients, andtracking_table_periodic_sweepfunctions totracking.c.tracking_table_periodic_sweepfunction to periodically call the sweeper to clean up dead client IDs.Testing:
./run_test.shPlease review and test this PR to ensure the fix is correct and effective."