Skip to content

Commit

Permalink
Merge pull request robinrodricks#838 from jnyrup/Dispose_Cancellation…
Browse files Browse the repository at this point in the history
…TokenSource

Dispose CancellationTokenSource
  • Loading branch information
robinrodricks authored Feb 13, 2022
2 parents 209cfaf + f56828b commit 14e882b
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 14e882b

Please sign in to comment.