Bug 58420 - Race condition of reflection.c
Summary: Race condition of reflection.c
Status: RESOLVED INVALID
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-26 21:28 UTC by Armin
Modified: 2017-07-28 17:53 UTC (History)
4 users (show)

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


Attachments
Stack traces (22.84 KB, text/plain)
2017-07-26 21:28 UTC, Armin
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 INVALID

Description Armin 2017-07-26 21:28:43 UTC
Created attachment 23826 [details]
Stack traces

TSan highlighted another race that I would like to discuss - commit 5d9d139e0ac4ecbf02c70cbce5d9a0c65a43faa4 and metadata/reflection.c. Please find TSan's stack traces attached and I highlighted the affected rows with "!":

gboolean reflected_equal (gconstpointer a, gconstpointer b) {
  // ...
! return (ea->item == eb->item) && (ea->refclass == eb->refclass);
}

static inline MonoObjectHandle cache_object_handle (MonoDomain *domain, MonoClass *klass, gpointer item, MonoObjectHandle o) {
  // ...
  mono_domain_lock (domain);
  // ...
! e->item = item;
! e->refclass = klass;
  // ...
  mono_domain_unlock (domain);
  // ...
}

I am not entirely sure if there is a mechanism that prevents `reflected_equal ()` from reading a half initialised `ReflectedEntry e`.
Comment 1 Ludovic Henry 2017-07-28 17:53:48 UTC
A race shouldn't happen since we allocate and initialise the ReflectedEntry *before* inserting it into `domain->refobject_hash`.

Rodrigo, could you please confirm?