From bbf5dc2785d7da2c0a269823e9175cb4c418676e Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 18 Sep 2024 08:47:26 +0200 Subject: [PATCH] Ensure WaitToWriteAsync is deterministic (in that it will not wait forever if no drain happens) --- src/Elastic.Channels/BufferedChannelBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Channels/BufferedChannelBase.cs b/src/Elastic.Channels/BufferedChannelBase.cs index 2df7e48..ae2128c 100644 --- a/src/Elastic.Channels/BufferedChannelBase.cs +++ b/src/Elastic.Channels/BufferedChannelBase.cs @@ -209,7 +209,7 @@ await ConsumeInboundEventsAsync(BatchExportSize, BufferOptions.OutboundBufferMax public override async ValueTask WaitToWriteAsync(CancellationToken ctx = default) { if (BufferOptions.BoundedChannelFullMode == BoundedChannelFullMode.Wait && _inflightEvents >= BufferOptions.InboundBufferMaxSize - DrainSize) - while (_inflightEvents >= (BufferOptions.InboundBufferMaxSize - DrainSize)) + for (var i = 0; i < 10 && _inflightEvents >= BufferOptions.InboundBufferMaxSize - DrainSize; i++) await Task.Delay(TimeSpan.FromMilliseconds(100), ctx).ConfigureAwait(false); return await InChannel.Writer.WaitToWriteAsync(ctx).ConfigureAwait(false); }