Bug 45991 - System.ComponentModel.LicenseManager.Validate is not thread safe
Summary: System.ComponentModel.LicenseManager.Validate is not thread safe
Status: RESOLVED FEATURE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.6.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-10-27 08:41 UTC by Tobias Loose
Modified: 2016-10-28 11:17 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Triggers the race condition (981 bytes, text/plain)
2016-10-27 08:41 UTC, Tobias Loose
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Tobias Loose 2016-10-27 08:41:33 UTC
Created attachment 18245 [details]
Triggers the race condition

Static methods of System.ComponentModel.LicenseManager ought to be thread safe [1].
System.ComponentModel.LicenseManager.Validate is one of those methods [2]

Unfortunately, this method is not thread safe as ends up using Hashtable internally (you will find the full stack trace attached):

  at System.Collections.Hashtable.Insert
  at System.Collections.Hashtable.set_Item
  at System.ComponentModel.LicenseManager.CacheProvider
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive
  at System.ComponentModel.LicenseManager.ValidateInternal
  at System.ComponentModel.LicenseManager.Validate

which causes:

[ERROR] FATAL UNHANDLED EXCEPTION: System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.




[1] https://msdn.microsoft.com/de-de/library/system.componentmodel.licensemanager(v=vs.110).aspx
[2] https://msdn.microsoft.com/de-de/library/system.componentmodel.licensemanager(v=vs.110).aspx
Comment 1 Tobias Loose 2016-10-27 08:43:18 UTC
Complete stack trace:

Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__2 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
   --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks, System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00242] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks, System.Int32 millisecondsTimeout) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Parallel.Invoke (System.Threading.Tasks.ParallelOptions parallelOptions, System.Action[] actions) [0x0033a] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
---> (Inner Exception #0) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__2 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---

---> (Inner Exception #1) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__3 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---

---> (Inner Exception #2) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__4 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---

[ERROR] FATAL UNHANDLED EXCEPTION: System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__2 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
   --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks, System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00242] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks, System.Int32 millisecondsTimeout) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.WaitAll (System.Threading.Tasks.Task[] tasks) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Parallel.Invoke (System.Threading.Tasks.ParallelOptions parallelOptions, System.Action[] actions) [0x0033a] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
---> (Inner Exception #0) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__2 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---

---> (Inner Exception #1) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__3 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---

---> (Inner Exception #2) System.TypeInitializationException: The type initializer for 'Licensed`1' threw an exception. ---> System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
  at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x00330] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Collections.Hashtable.set_Item (System.Object key, System.Object value) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.ComponentModel.LicenseManager.CacheProvider (System.Type type, System.ComponentModel.LicenseProvider provider) [0x0001a] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternalRecursive (System.ComponentModel.LicenseContext context, System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license, System.String& licenseKey) [0x00055] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.ValidateInternal (System.Type type, System.Object instance, System.Boolean allowExceptions, System.ComponentModel.License& license) [0x00005] in <59be416de143456b88b9988284f43350>:0
  at System.ComponentModel.LicenseManager.Validate (System.Type type) [0x00000] in <59be416de143456b88b9988284f43350>:0
  at ReproduceRace.Program+Licensed`1[T]..cctor () [0x00020] in <a646a42cfbf44386bb1d86ea835de46d>:0
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at ReproduceRace.Program.<Main>m__4 () [0x00000] in <a646a42cfbf44386bb1d86ea835de46d>:0
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 <---
Comment 2 Marek Safar 2016-10-28 11:17:04 UTC
We are using same code as .net for this class therefore you can same behaviour and documentation is out of date.