Skip to content

Commit

Permalink
Dispose CancellationTokenSource
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Feb 7, 2022
1 parent 22c896b commit f56828b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions FluentFTP/Streams/FtpSocketStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,16 +979,18 @@ public async Task ConnectAsync(string host, int port, FtpIpVersion ipVersions, C
#if CORE
if (this.ConnectTimeout > 0)
{
var timeoutSrc = new CancellationTokenSource();
timeoutSrc.CancelAfter(this.ConnectTimeout);

var tokenSrc = CancellationTokenSource.CreateLinkedTokenSource(
token, timeoutSrc.Token);
token = tokenSrc.Token;
using (var timeoutSrc = CancellationTokenSource.CreateLinkedTokenSource(token))
{
timeoutSrc.CancelAfter(this.ConnectTimeout);
await EnableCancellation(m_socket.ConnectAsync(addresses[i], port), timeoutSrc.Token, () => CloseSocket());
break;
}
}
else
{
await EnableCancellation(m_socket.ConnectAsync(addresses[i], port), token, () => CloseSocket());
break;
}

await EnableCancellation(m_socket.ConnectAsync(addresses[i], port), token, () => CloseSocket());
break;
#else
var connectResult = m_socket.BeginConnect(addresses[i], port, null, null);
await EnableCancellation(Task.Factory.FromAsync(connectResult, m_socket.EndConnect), token, () => CloseSocket());
Expand Down

0 comments on commit f56828b

Please sign in to comment.