HSETEXPIRE with an overflowing TTL returns OK and deletes the whole hash

Open Beginner friendly
#3,698 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@anubhavgupta121 is already working on this.

Since Oct 19, 2026.

  • #3699 by @anubhavgupta121 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, redis
Domain
backend, databases

Research direction

Start with CommandHSetExpire in src/commands/cmd_hash.cc and trace how its parsed TTL reaches Hash::MSet and the key expiration metadata. Compare the overflow handling with the related SET ... EX issue #3674 and PR #3680. Done means an overflowing TTL returns an invalid expire time error and leaves the existing hash unchanged; the payload names no test file.

Written by the indexing model from the issue text.

Description

bug
Search before asking
  • I had searched in the issues and found no similar issues.
Version

unstable, commit d8aeed4 (Linux x86_64)

Minimal reproduce step

HSET h f1 v1
HSETEXPIRE h 18446744073709551 f2 v2
HGETALL h
EXISTS h

What did you expect to see?

An invalid expire time error, with h unchanged (f1 -> v1, no TTL).

What did you see instead?

HSETEXPIRE returns OK, HGETALL is empty and EXISTS returns 0. Both the new field and the existing f1 are gone.

Anything Else?

CommandHSetExpire in src/commands/cmd_hash.cc parses the TTL as uint64_t with no upper bound, then passes ttl_ * 1000 + util::GetTimeStampMS() to Hash::MSet, which sets it as the key's metadata expire.

With ttl = 18446744073709551, ttl * 1000 is just under 2^64. Adding the current time wraps it to a moment in the past, so the whole hash expires immediately. 18446744073709551615 behaves the same way.

This is the same class of bug as #3674 (SET ... EX overflow). PR #3680 does not cover HSETEXPIRE. SET k v EX 9223372036854775807 from #3674 also reproduces on the same build.

Are you willing to submit a PR?
  • I'm willing to submit a PR!
Dominant language
C++
Stars
4.5k
Forks
686
Avg merge
2d 13h
Merged PRs (30d)
40

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/kvrocks

All issues in apache/kvrocks

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.