Fixing that disposed shell context were later accessed because of lazy enumerations.

Aka fixing the fix's improvement's fix.
This commit is contained in:
Lombiq
2014-08-14 00:35:54 +02:00
committed by Zoltán Lehóczky
parent 64eb4725bc
commit 780fc2a15f

View File

@@ -277,22 +277,25 @@ namespace Orchard.Environment {
// terminate the shell if the tenant was disabled
else if (settings.State == TenantState.Disabled) {
shellContext.Shell.Terminate();
shellContext.Dispose();
_runningShellTable.Remove(settings);
_shellContexts = _shellContexts.Where(shell => shell.Settings.Name != settings.Name);
// Forcing enumeration with ToArray() so a lazy execution isn't causing issues by accessing the disposed context.
_shellContexts = _shellContexts.Where(shell => shell.Settings.Name != settings.Name).ToArray();
shellContext.Dispose();
}
// reload the shell as its settings have changed
else {
// dispose previous context
shellContext.Shell.Terminate();
shellContext.Dispose();
var context = _shellContextFactory.CreateShellContext(settings);
// activate and register modified context
_shellContexts = _shellContexts.Where(shell => shell.Settings.Name != settings.Name).Union(new[] { context });
// Sctivate and register modified context.
// Forcing enumeration with ToArray() so a lazy execution isn't causing issues by accessing the disposed shell context.
_shellContexts = _shellContexts.Where(shell => shell.Settings.Name != settings.Name).Union(new[] { context }).ToArray();
shellContext.Dispose();
context.Shell.Activate();
_runningShellTable.Update(settings);