Skip to content

Commit 4e702bc

Browse files
authored
Skip cleanup of eventpipe for mono to prevent crashes on shutdown (#100938)
1 parent 34920ed commit 4e702bc

File tree

3 files changed

+14
-72
lines changed

3 files changed

+14
-72
lines changed

src/mono/mono/eventpipe/ep-rt-mono-profiler-provider.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,9 +3030,6 @@ void
30303030
ep_rt_mono_profiler_provider_fini (void)
30313031
{
30323032
if (_mono_profiler_provider_enabled) {
3033-
if (_mono_profiler_provider_callspec.enabled)
3034-
mono_callspec_cleanup (&_mono_profiler_provider_callspec);
3035-
30363033
if (_mono_profiler_provider) {
30373034
mono_profiler_set_gc_root_register_callback (_mono_profiler_provider, NULL);
30383035
mono_profiler_set_gc_root_unregister_callback (_mono_profiler_provider, NULL);
@@ -3100,7 +3097,6 @@ ep_rt_mono_profiler_provider_fini (void)
31003097

31013098
mono_profiler_set_call_instrumentation_filter_callback (_mono_profiler_provider, NULL);
31023099
}
3103-
_mono_profiler_provider = NULL;
31043100

31053101
if (_mono_heap_dump_profiler_provider) {
31063102
mono_profiler_set_gc_root_register_callback (_mono_heap_dump_profiler_provider, NULL);
@@ -3110,21 +3106,16 @@ ep_rt_mono_profiler_provider_fini (void)
31103106
mono_profiler_set_gc_resize_callback (_mono_heap_dump_profiler_provider, NULL);
31113107
mono_profiler_set_gc_finalized_callback (_mono_heap_dump_profiler_provider, NULL);
31123108
}
3113-
_mono_heap_dump_profiler_provider = NULL;
31143109

31153110
_gc_heap_dump_requests = 0;
31163111
_gc_heap_dump_in_progress = 0;
31173112
_gc_heap_dump_trigger_count = 0;
31183113
_gc_state = 0;
3119-
3120-
_mono_profiler_provider_enabled = DEFAULT_MONO_PROFILER_PROVIDER_ENABLED;
3121-
3122-
gc_heap_dump_mem_block_free_all ();
3123-
3124-
gc_heap_dump_request_params_free ();
3125-
provider_params_free ();
3126-
3127-
ep_rt_spin_lock_free (&_gc_lock);
3114+
3115+
// We were cleaning up resources (mutexes, tls data, etc) here but it races with
3116+
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
3117+
// and not leaking these threads becomes a priority we will have to reimplement
3118+
// cleanup here.
31283119
}
31293120
}
31303121

src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4630,26 +4630,10 @@ ep_rt_mono_runtime_provider_init (void)
46304630
void
46314631
ep_rt_mono_runtime_provider_fini (void)
46324632
{
4633-
if (_sampled_thread_callstacks)
4634-
g_array_free (_sampled_thread_callstacks, TRUE);
4635-
_sampled_thread_callstacks = NULL;
4636-
4637-
_max_sampled_thread_count = 32;
4638-
4639-
g_free (_runtime_helper_compile_method_jitinfo);
4640-
_runtime_helper_compile_method_jitinfo = NULL;
4641-
4642-
if (_runtime_helper_compile_method)
4643-
mono_free_method (_runtime_helper_compile_method);
4644-
_runtime_helper_compile_method = NULL;
4645-
4646-
g_free (_monitor_enter_method_jitinfo);
4647-
_monitor_enter_method_jitinfo = NULL;
4648-
_monitor_enter_method = NULL;
4649-
4650-
g_free (_monitor_enter_v4_method_jitinfo);
4651-
_monitor_enter_v4_method_jitinfo = NULL;
4652-
_monitor_enter_v4_method = NULL;
4633+
// We were cleaning up resources (mutexes, tls data, etc) here but it races with
4634+
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
4635+
// and not leaking these threads becomes a priority we will have to reimplement
4636+
// cleanup here.
46534637

46544638
if (_ep_rt_mono_default_profiler_provider) {
46554639
mono_profiler_set_jit_begin_callback (_ep_rt_mono_default_profiler_provider, NULL);
@@ -4680,14 +4664,6 @@ ep_rt_mono_runtime_provider_fini (void)
46804664
_gc_heap_dump_requests = 0;
46814665
_gc_heap_dump_count = 0;
46824666
_gc_heap_dump_trigger_count = 0;
4683-
4684-
dn_vector_dispose (&_gc_heap_dump_requests_data);
4685-
memset (&_gc_heap_dump_requests_data, 0, sizeof (_gc_heap_dump_requests_data));
4686-
4687-
dn_umap_dispose (&_gc_roots_table);
4688-
memset (&_gc_roots_table, 0, sizeof (_gc_roots_table));
4689-
4690-
ep_rt_spin_lock_free (&_gc_lock);
46914667
}
46924668

46934669
void

src/mono/mono/eventpipe/ep-rt-mono.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -852,44 +852,19 @@ ep_rt_mono_init_finish (void)
852852
void
853853
ep_rt_mono_fini (void)
854854
{
855-
// Avoid cleaning up resources to prevent cleaning up out from under running
856-
// threads.
857-
if (!mono_runtime_is_shutting_down ())
858-
return;
859-
860855
ep_rt_mono_runtime_provider_fini ();
861856
ep_rt_mono_profiler_provider_fini ();
862857

863-
if (_eventpipe_initialized)
864-
mono_rand_close (_rand_provider);
865-
866-
_rand_provider = NULL;
867-
_eventpipe_initialized = FALSE;
868-
869-
_ep_rt_mono_runtime_initialized = FALSE;
870-
871858
if (_ep_rt_mono_default_profiler_provider) {
872859
mono_profiler_set_runtime_initialized_callback (_ep_rt_mono_default_profiler_provider, NULL);
873860
mono_profiler_set_thread_started_callback (_ep_rt_mono_default_profiler_provider, NULL);
874861
mono_profiler_set_thread_stopped_callback (_ep_rt_mono_default_profiler_provider, NULL);
875862
}
876-
_ep_rt_mono_default_profiler_provider = NULL;
877-
878-
if (_ep_rt_mono_thread_holder_tls_id)
879-
mono_native_tls_free (_ep_rt_mono_thread_holder_tls_id);
880-
_ep_rt_mono_thread_holder_tls_id = 0;
881-
882-
if (_thread_data_tls_id)
883-
mono_native_tls_free (_thread_data_tls_id);
884-
_thread_data_tls_id = 0;
885-
886-
_ep_rt_mono_os_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
887-
_ep_rt_mono_os_cmd_line = NULL;
888-
889-
_ep_rt_mono_managed_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
890-
_ep_rt_mono_managed_cmd_line = NULL;
891-
892-
ep_rt_spin_lock_free (&_ep_rt_mono_config_lock);
863+
864+
// We were cleaning up resources (mutexes, tls data, etc) here but it races with
865+
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
866+
// and not leaking these threads becomes a priority we will have to reimplement
867+
// cleanup here.
893868
}
894869

895870
void

0 commit comments

Comments
 (0)