Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/NATS.Client.JetStream/Internal/NatsJSOrderedPushConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ internal record NatsJSOrderedPushConsumerOpts
public ConsumerConfigDeliverPolicy DeliverPolicy { get; init; } = ConsumerConfigDeliverPolicy.All;

public bool HeadersOnly { get; init; } = false;

/// <summary>
/// Timeout for cleanup operations during disposal (e.g. deleting ephemeral consumers).
/// If the server is slow or unresponsive, disposal will not block longer than this.
/// </summary>
public TimeSpan CleanupTimeout { get; init; } = TimeSpan.FromSeconds(5);
}

internal class NatsJSOrderedPushConsumer<T>
Expand Down Expand Up @@ -158,7 +164,20 @@ public async ValueTask DisposeAsync()

_msgChannel.Writer.TryComplete();

await _context.DeleteConsumerAsync(_stream, Consumer, _cancellationToken);
using var cts = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken);
cts.CancelAfter(_opts.CleanupTimeout);
try
{
await _context.DeleteConsumerAsync(_stream, Consumer, cts.Token);
}
catch (OperationCanceledException)
{
// Timeout - server will clean up ephemeral consumer automatically
}
catch (NatsJSApiException)
{
// Consumer may already be gone, that's fine
}
}

internal void Init()
Expand Down
Loading