Skip to content

Commit

Permalink
Ensure WaitToWriteAsync is deterministic (in that it will not wait fo…
Browse files Browse the repository at this point in the history
…rever if no drain happens)
  • Loading branch information
Mpdreamz committed Sep 18, 2024
1 parent 55ebdc4 commit bbf5dc2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Elastic.Channels/BufferedChannelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ await ConsumeInboundEventsAsync(BatchExportSize, BufferOptions.OutboundBufferMax
public override async ValueTask<bool> 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);
}
Expand Down

0 comments on commit bbf5dc2

Please sign in to comment.