U4-2738 - Collection Disposal issue when deploying 6.1.4 on Windows Server 2008 (Random, environment specific)

Created by Nik Wahlberg 29 Aug 2013, 01:35:26 Updated by Sebastiaan Janssen 30 Sep 2013, 12:50:42

We have upgraded a 4.11.10 install to 6.1.4 and everything is running fine locally. When deploying the upgraded application to the staging server (where the current 4.11.10 is running fine), we can't run the application. The following error is shown:

Server Error in '/' Application.

Collection was modified; enumeration operation may not execute. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Collection was modified; enumeration operation may not execute.] System.Collections.HashtableEnumerator.MoveNext() +222 Umbraco.Web.UmbracoModule.DisposeHttpContextItems(HttpContext http) +264 Umbraco.Web.UmbracoModule.b__9(Object sender, EventArgs args) +360 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +163 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +417

A temporary fix seems to be to wrap disposal code in try/catch:

private static void DisposeHttpContextItems(HttpContext http) { try { foreach (DictionaryEntry i in http.Items) { i.Value.DisposeIfDisposable(); i.Key.DisposeIfDisposable(); } } catch(Exception ex) }

NOTE: found in Umbraco-CMS-release-6.1.4\src\Umbraco.Web\UmbracoModule.cs

Thanks!

1 Attachments

Comments

Trevor Loader 03 Sep 2013, 02:22:50

We too are on Win 2008 R2 and have the same issue. It is not just confined to upgraded installations as I've tested clean installs and any version after v6.1.3 has this problem. I can confirm that this issue exists for v6.1.4, v6.1.5 and v6.2.0 (dated 29th Aug).


Stephan 03 Sep 2013, 06:44:53

@Shan: looks like the HttpContext items collection can be modified while '''DisposeHttpContextItems''' is running, ie while '''EndRequest''' is running?!


Shannon Deminick 03 Sep 2013, 06:47:17

If we dispose using an integer iteration instead of a foreach it will fix it. Not sure why this is only doing that on win server 2008, it also indicates that we are adding/removing items from the collection (that is what that error means) but we are not.


Stephan 03 Sep 2013, 06:52:46

Or iterate over a shallow clone.

''but we are not''... can we be 100% sure that none of the items we're disposing is altering the items collection when being disposed?


Shannon Deminick 03 Sep 2013, 06:58:33

That would be strange but even if that was happening we wouldn't get this YSOD. This YSOD occurs because the collection is being modified in a foreach loop which is using the GetEnumerator method. If we use a for loop with an int iteration the YSOD won't occur... if the disposal itself is modifying the collection it's contained in (mind explodes), then we can do it a different way and just track each key that is IDisposable itself and/or has a value that is IDisposable, then we can iterate over the tracked keys and dispose based on that.


Shannon Deminick 03 Sep 2013, 07:19:37

Have fixed this in rev:

eeeb99b3b53272b167c952e29b7e07c0788cb18b


Shannon Deminick 03 Sep 2013, 07:20:24

Will wait to see if anyone can confirm if somehow this error is still happening in server 2k8... and to ensure that its not logging errors either.


Emil Rasmussen 03 Sep 2013, 11:43:12

We experienced this issue on a developer machine running Windows 7. We applied the patch to 6.1.5 and everything is working again. We are planning on deploying to live in a couple of days, I will report back if things get ugly. But the patch seems relatively safe to apply.


Trevor Loader 03 Sep 2013, 19:56:47

I can confirm that the issue has been fixed (for me at least) in Build #53. Thanks everyone for a quick fix!


Priority: Major

Type: Exception

State: Fixed

Assignee: Shannon Deminick

Difficulty: Difficult

Category: Installation

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.4, 6.1.5

Due in version: 6.1.6

Sprint:

Story Points:

Cycle: