Skip to content

store: make valkey UpdateSessionLastActivity atomic - #511

Open
altf4-games wants to merge 1 commit into
volcano-sh:mainfrom
altf4-games:fix/valkey-last-activity-atomic
Open

altf4-games wants to merge 1 commit into
volcano-sh:mainfrom
altf4-games:fix/valkey-last-activity-atomic

Conversation

@altf4-games

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

valkeyStore.UpdateSessionLastActivity checks the session key with EXISTS and then runs ZADD on the last-activity index as a separate command. If the session gets deleted between the two (by GC, or a DELETE request calling DeleteSandboxBySessionID), the ZADD puts the deleted session back into the index and the call still returns nil. The router calls this after every proxied request, so a session deleted while a request is in flight can hit it. The leftover member has no session key, which is the orphaned entry problem in #491.

#358 fixed the same pattern in the redis store with a Lua script, and @hzxuzhonghu asked there for the valkey store to get the same change in a follow-up. This is that follow-up. It only affects STORE_TYPE=valkey; redis is the default.

Changes:

  • The Lua script source is now one shared updateSessionLastActivityLua constant used by both stores, so they can't drift apart again.
  • The valkey store runs it with valkey.NewLuaScript(...).Exec. A missing session still returns ErrNotFound.
  • New test TestValkeyStore_UpdateSessionLastActivity_ConcurrentDelete. A client wrapper runs DeleteSandboxBySessionID right after the first round trip, once with the script not yet cached (EVAL fallback) and once cached (EVALSHA). It fails on main, where the deleted session ends up back in the index, and passes with this change.

This stops new orphaned entries from being created this way. Cleaning up existing ones is #495.

Which issue(s) this PR fixes:
Refs #358, #491

Special notes for your reviewer:

I ran go test -race ./pkg/store, the pkg/workloadmanager and pkg/router tests, and make lint.
AI use: I used Claude to help find the bug and draft the fix and the test. I reviewed and ran all of it and can explain each line.

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: Pradyum Mistry <39883432+altf4-games@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 14:46
@volcano-sh-bot volcano-sh-bot added the kind/bug Something isn't working label Nov 11, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.85%. Comparing base (f521ae9) to head (e103f07).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
pkg/store/store_valkey.go 83.33% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #511      +/-   ##
==========================================
+ Coverage   60.45%   63.85%   +3.40%     
==========================================
  Files          35       35              
  Lines        3616     3655      +39     
==========================================
+ Hits         2186     2334     +148     
+ Misses       1211     1090     -121     
- Partials      219      231      +12     
Flag Coverage Δ
unittests 63.85% <83.33%> (+3.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants