Skip to content

Commit 861210a

Browse files
committed
Use task completion source to avoid ever-increasing number of timers
1 parent 7c5484b commit 861210a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/FubarDev.FtpServer/FtpConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ protected override async Task<int> ReadFromStreamAsync(byte[] buffer, int offset
701701
var readTask = Stream
702702
.ReadAsync(buffer, offset, length, cancellationToken);
703703

704-
// We ensure that this service can be closed ASAP with the help
705-
// of a Task.Delay.
706-
var resultTask = await Task.WhenAny(readTask, Task.Delay(-1, cancellationToken))
704+
var tcs = new TaskCompletionSource<object?>();
705+
using var registration = cancellationToken.Register(() => tcs.TrySetResult(null));
706+
var resultTask = await Task.WhenAny(readTask, tcs.Task)
707707
.ConfigureAwait(false);
708708
if (resultTask != readTask || cancellationToken.IsCancellationRequested)
709709
{

0 commit comments

Comments
 (0)