mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Merge pull request #2546 from ripienaar/negative_dupe_window_protection
protect against negative dupe window via negative max age
This commit is contained in:
@@ -13101,6 +13101,39 @@ func TestJetStreamPullLargeBatchExpired(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNegativeDupeWindow(t *testing.T) {
|
||||
s := RunBasicJetStreamServer()
|
||||
defer s.Shutdown()
|
||||
|
||||
config := s.JetStreamConfig()
|
||||
if config != nil {
|
||||
defer removeDir(t, config.StoreDir)
|
||||
}
|
||||
|
||||
nc, js := jsClientConnect(t, s)
|
||||
defer nc.Close()
|
||||
|
||||
// we incorrectly set MaxAge to -1 which then as a side effect sets dupe window to -1 which should fail
|
||||
_, err := js.AddStream(&nats.StreamConfig{
|
||||
Name: "TEST",
|
||||
Subjects: nil,
|
||||
Retention: nats.WorkQueuePolicy,
|
||||
MaxConsumers: 1,
|
||||
MaxMsgs: -1,
|
||||
MaxBytes: -1,
|
||||
Discard: nats.DiscardNew,
|
||||
MaxAge: -1,
|
||||
MaxMsgsPerSubject: -1,
|
||||
MaxMsgSize: -1,
|
||||
Storage: nats.FileStorage,
|
||||
Replicas: 1,
|
||||
NoAck: false,
|
||||
})
|
||||
if err == nil || err.Error() != "duplicates window can not be negative" {
|
||||
t.Fatalf("Expected dupe window error got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Simple JetStream Benchmarks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -805,7 +805,8 @@ func checkStreamCfg(config *StreamConfig) (StreamConfig, error) {
|
||||
} else {
|
||||
cfg.Duplicates = StreamDefaultDuplicatesWindow
|
||||
}
|
||||
} else if cfg.Duplicates < 0 {
|
||||
}
|
||||
if cfg.Duplicates < 0 {
|
||||
return StreamConfig{}, fmt.Errorf("duplicates window can not be negative")
|
||||
}
|
||||
// Check that duplicates is not larger then age if set.
|
||||
|
||||
Reference in New Issue
Block a user