Skip to content

Commit

Permalink
FIX : PurgeDeletesAsync hangs if KV Bucket is already empty (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwatchuk authored Apr 25, 2024
1 parent 65ef7c5 commit 660194e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NATS.Client.KeyValueStore/NatsKVStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ public async ValueTask PurgeDeletesAsync(NatsKVPurgeOpts? opts = default, Cancel
// Type doesn't matter here, we're just using the watcher to get the keys
await using (var watcher = await WatchInternalAsync<int>(">", opts: new NatsKVWatchOpts { MetaOnly = true }, cancellationToken: cancellationToken))
{
if (watcher.InitialConsumer.Info.NumPending == 0)
return;

while (await watcher.Entries.WaitToReadAsync(cancellationToken).ConfigureAwait(false))
{
while (watcher.Entries.TryRead(out var entry))
Expand Down
3 changes: 3 additions & 0 deletions tests/NATS.Client.KeyValueStore.Tests/KeyValueStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ public async Task Purge_deletes()

_output.WriteLine($"COUNT={count}");
Assert.Equal(0, count);

_output.WriteLine("PURGE ALL DELETES ON EMPTY BUCKET");
await store.PurgeDeletesAsync(opts: new NatsKVPurgeOpts { DeleteMarkersThreshold = TimeSpan.Zero }, cancellationToken: cancellationToken);
}

[Fact]
Expand Down

0 comments on commit 660194e

Please sign in to comment.