Bug 29906 - Static method TimeZoneInfo.GetSystemTimeZones() is not thread safe.
Summary: Static method TimeZoneInfo.GetSystemTimeZones() is not thread safe.
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-05-09 16:27 UTC by af4178a2
Modified: 2015-11-08 08:16 UTC (History)
3 users (show)

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

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:

Description af4178a2 2015-05-09 16:27:07 UTC
If multiple threads are concurrently calling TimeZoneInfo.GetSystemTimeZones() the faster thread initializes the static field "systemTimeZones" and populates the list. A slower thread either immediatelly retrieves an indirect reference to the same list which is still populated by the first thread or instantiates the field and populates the list itself again.

Consider to lock the block which is responsible for initializing the static field "systemTimeZones" until it is completely populated.

The problem still exists in the latest mono/master branch. A short look to the code and you can see the problem immediately.

642			private static List<TimeZoneInfo> systemTimeZones;
643			public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
644			{
645				if (systemTimeZones == null) {
646				systemTimeZones = new List<TimeZoneInfo> ();
...				// list is populated
694				}
695				return new ReadOnlyCollection<TimeZoneInfo> (systemTimeZones);
696			}
Comment 1 Marek Safar 2015-05-25 08:57:24 UTC
Fixed in master