From bbb08eafc448818b5bc98202be67dc7d8ce81535 Mon Sep 17 00:00:00 2001 From: rickdotnet Date: Sun, 3 Mar 2024 08:47:32 -0600 Subject: [PATCH] Prevent KeyValueStore error when MaxAge is set below the default DuplicateWindow value --- src/NATS.Client.KeyValueStore/NatsKVContext.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/NATS.Client.KeyValueStore/NatsKVContext.cs b/src/NATS.Client.KeyValueStore/NatsKVContext.cs index 8973235e7..cfded0200 100644 --- a/src/NATS.Client.KeyValueStore/NatsKVContext.cs +++ b/src/NATS.Client.KeyValueStore/NatsKVContext.cs @@ -108,9 +108,13 @@ public async ValueTask CreateStoreAsync(NatsKVConfig config, Cance // MirrorDirect = // Mirror = Retention = StreamConfigRetention.Limits, // from ADR-8 - DuplicateWindow = TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8 + DuplicateWindow = config.MaxAge != default ? config.MaxAge : TimeSpan.FromMinutes(2), // 120_000_000_000ns, from ADR-8 }; + // https://github.com/nats-io/nats.go/blob/98430acd80423b776149f29d625d158f490ac3c5/jetstream/kv.go#L334-L342 + if (streamConfig.MaxAge > TimeSpan.Zero && streamConfig.MaxAge < streamConfig.DuplicateWindow) + streamConfig.DuplicateWindow = streamConfig.MaxAge; + var stream = await _context.CreateStreamAsync(streamConfig, cancellationToken); return new NatsKVStore(config.Bucket, _context, stream);