Skip to content

Commit

Permalink
Use Nats-TTL: never for never expires
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <[email protected]>
  • Loading branch information
neilalexander committed Jan 3, 2025
1 parent 1df042c commit 266f616
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25029,7 +25029,7 @@ func TestJetStreamMessageTTLNeverExpire(t *testing.T) {

// The first message we publish is set to "never expire", therefore it
// won't age out with the MaxAge policy.
msg.Header.Set("Nats-TTL", "-1")
msg.Header.Set("Nats-TTL", "never")
_, err := js.PublishMsg(msg)
require_NoError(t, err)

Expand Down
13 changes: 12 additions & 1 deletion server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4215,14 +4215,25 @@ func getMessageTTL(hdr []byte) (int64, error) {
return 0, nil
}
sttl := bytesToString(ttl)
if strings.ToLower(sttl) == "never" {
return -1, nil
}
dur, err := time.ParseDuration(sttl)
if err == nil {
if dur < time.Second {
return 0, NewJSMessageTTLInvalidError()
}
return int64(dur.Seconds()), nil
}
return parseInt64(ttl), nil
t := parseInt64(ttl)
if t < 0 {
// This probably means a parse failure, hence why
// we have a special case "never" for returning -1.
// Otherwise we can't know if it's a genuine TTL
// that says never expire or if it's a parse error.
return 0, NewJSMessageTTLInvalidError()
}
return t, nil
}

// Signal if we are clustered. Will acquire rlock.
Expand Down

0 comments on commit 266f616

Please sign in to comment.