Skip to content

Commit

Permalink
[FIXED] JetStream would exceed limits calculation (#6264)
Browse files Browse the repository at this point in the history
The calculation should check if the current total plus what we want to
store exceeds the max.

Signed-off-by: Maurice van Veen <[email protected]>
  • Loading branch information
derekcollison authored Dec 16, 2024
2 parents 5431acb + cc4e175 commit 7bd91dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ func (js *jetStream) wouldExceedLimits(storeType StorageType, sz int) bool {
} else {
total, max = &js.storeUsed, js.config.MaxStore
}
return atomic.LoadInt64(total) > (max + int64(sz))
return (atomic.LoadInt64(total) + int64(sz)) > max
}

func (js *jetStream) limitsExceeded(storeType StorageType) bool {
Expand Down
16 changes: 16 additions & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24721,3 +24721,19 @@ func TestJetStreamMemoryPurgeClearsSubjectsState(t *testing.T) {
require_NoError(t, err)
require_Len(t, len(si.State.Subjects), 0)
}

func TestJetStreamWouldExceedLimits(t *testing.T) {
s := RunBasicJetStreamServer(t)
defer s.Shutdown()

js := s.getJetStream()
require_NotNil(t, js)

// Storing exactly up to the limit should work.
require_False(t, js.wouldExceedLimits(MemoryStorage, int(js.config.MaxMemory)))
require_False(t, js.wouldExceedLimits(FileStorage, int(js.config.MaxStore)))

// Storing one more than the max should exceed limits.
require_True(t, js.wouldExceedLimits(MemoryStorage, int(js.config.MaxMemory)+1))
require_True(t, js.wouldExceedLimits(FileStorage, int(js.config.MaxStore)+1))
}

0 comments on commit 7bd91dc

Please sign in to comment.