[release/2.2] Backport memory leak fix from 3.0 (#13840)
This commit is contained in:
parent
3bb7be15d8
commit
59bdc3449f
|
|
@ -78,6 +78,7 @@ Later on, this will be checked using this condition:
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(VersionPrefix)' == '2.2.8' ">
|
||||
<PackagesInPatch>
|
||||
Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
|
||||
</PackagesInPatch>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -42,8 +42,10 @@ namespace Microsoft.AspNetCore.DataProtection.EntityFrameworkCore
|
|||
{
|
||||
using (var scope = _services.CreateScope())
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||
return context.DataProtectionKeys.AsNoTracking().Select(key => TryParseKeyXml(key.Xml)).ToList().AsReadOnly();
|
||||
var context = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||
// Put logger in a local such that `this` isn't captured.
|
||||
var logger = _logger;
|
||||
return context.DataProtectionKeys.AsNoTracking().Select(key => TryParseKeyXml(key.Xml, logger)).ToList().AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +67,7 @@ namespace Microsoft.AspNetCore.DataProtection.EntityFrameworkCore
|
|||
}
|
||||
}
|
||||
|
||||
private XElement TryParseKeyXml(string xml)
|
||||
private static XElement TryParseKeyXml(string xml, ILogger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -73,7 +75,7 @@ namespace Microsoft.AspNetCore.DataProtection.EntityFrameworkCore
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger?.LogExceptionWhileParsingKeyXml(xml, e);
|
||||
logger?.LogExceptionWhileParsingKeyXml(xml, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue