Skip to content

KV get returns expired value entry when TTL is enabled #1322

@burl21

Description

@burl21

Observed behavior

When using KeyValue with per-message TTL enabled, the following code snippet returns a non-null value even though the server has already deleted the key due to expiration:

var kve = kv.get(key);
// kve.getValue() is null
return kve != null && kve.getValue() != null
          ? converter.read(kve.getValue(), Object.class)
          : null;

Expected behavior

keyValue.get(key) should return null when the key has expired and been deleted by the server.

Server and client version

Server:

Version:  2.11.2
Git:      [55efd1d]
Name:     NBTPDMICKE5D3UTWIT4X3YFODFCSLTWJDX6HSQO5OUBAWPQ5RXXQ2EXM
Node:     LmBR30Xm
ID:       NBTPDMICKE5D3UTWIT4X3YFODFCSLTWJDX6HSQO5OUBAWPQ5RXXQ2EXM

Client: 2.21.2

Host environment

No response

Steps to reproduce

nats kv info long-cache:

Bucket Name           : long-cache
History Kept          : 1
Values Stored         : 1
Compressed            : false
Per-Key TTL Supported : true
Limit Marker TTL      : 1d0h0m0s
Backing Store Kind    : JetStream
Description           : Used for cache
Bucket Size           : 327 B
Maximum Bucket Size   : unlimited
Maximum Value Size    : unlimited
Maximum Age           : 1d0h0m0s
JetStream Stream      : KV_long-cache
Storage               : Memory

nats kv ls long-cache:

No keys found in bucket

Debug:
Image

kv.create(key, value, MessageTtl.seconds(20));

Sometimes we see:
Error while putting cache entry with key 'val.57c3e7f5bbee56f876e4cece2405b608'. wrong last sequence: 2 [10071]

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSuspected defect such as a bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions