Skip to content

Commit

Permalink
[FIXED] JetStream would exceed limits calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
  • Loading branch information
MauriceVanVeen authored and neilalexander committed Dec 16, 2024
1 parent dc96b75 commit ec1a7b4
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 @@ -2107,7 +2107,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 @@ -22981,3 +22981,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 ec1a7b4

Please sign in to comment.