Merge pull request #396 from sacgod/dev

Fix missing dispose of CTS during Request timeout handling
This commit is contained in:
Todd Menier 2018-11-27 11:44:56 -05:00 committed by GitHub
commit 1b072fce15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,11 +117,12 @@ namespace Flurl.Http
request.RequestUri = Url.ToUri(); // in case it was modifed in the handler above
var cancellationTokenWithTimeout = cancellationToken;
CancellationTokenSource timeoutTokenSource = null;
if (Settings.Timeout.HasValue) {
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(Settings.Timeout.Value);
cancellationTokenWithTimeout = cts.Token;
timeoutTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
timeoutTokenSource.CancelAfter(Settings.Timeout.Value);
cancellationTokenWithTimeout = timeoutTokenSource.Token;
}
call.StartedUtc = DateTime.UtcNow;
@ -146,6 +147,8 @@ namespace Flurl.Http
}
finally {
request.Dispose();
timeoutTokenSource?.Dispose();
if (Settings.CookiesEnabled)
ReadResponseCookies(call.Response);