Skip to content

Commit

Permalink
Prevent KeyValueStore error when MaxAge is set below the default Dupl…
Browse files Browse the repository at this point in the history
…icateWindow value (#362)
  • Loading branch information
rickdotnet committed Mar 11, 2024
1 parent 56f831f commit 5cbe4e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/NATS.Client.KeyValueStore/NatsKVContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ public async ValueTask<INatsKVStore> 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);
Expand Down

0 comments on commit 5cbe4e2

Please sign in to comment.