Skip to content

Commit

Permalink
Skip cleanup of eventpipe for mono to prevent crashes on shutdown (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
davmason authored Apr 13, 2024
1 parent 34920ed commit 4e702bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 72 deletions.
19 changes: 5 additions & 14 deletions src/mono/mono/eventpipe/ep-rt-mono-profiler-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,9 +3030,6 @@ void
ep_rt_mono_profiler_provider_fini (void)
{
if (_mono_profiler_provider_enabled) {
if (_mono_profiler_provider_callspec.enabled)
mono_callspec_cleanup (&_mono_profiler_provider_callspec);

if (_mono_profiler_provider) {
mono_profiler_set_gc_root_register_callback (_mono_profiler_provider, NULL);
mono_profiler_set_gc_root_unregister_callback (_mono_profiler_provider, NULL);
Expand Down Expand Up @@ -3100,7 +3097,6 @@ ep_rt_mono_profiler_provider_fini (void)

mono_profiler_set_call_instrumentation_filter_callback (_mono_profiler_provider, NULL);
}
_mono_profiler_provider = NULL;

if (_mono_heap_dump_profiler_provider) {
mono_profiler_set_gc_root_register_callback (_mono_heap_dump_profiler_provider, NULL);
Expand All @@ -3110,21 +3106,16 @@ ep_rt_mono_profiler_provider_fini (void)
mono_profiler_set_gc_resize_callback (_mono_heap_dump_profiler_provider, NULL);
mono_profiler_set_gc_finalized_callback (_mono_heap_dump_profiler_provider, NULL);
}
_mono_heap_dump_profiler_provider = NULL;

_gc_heap_dump_requests = 0;
_gc_heap_dump_in_progress = 0;
_gc_heap_dump_trigger_count = 0;
_gc_state = 0;

_mono_profiler_provider_enabled = DEFAULT_MONO_PROFILER_PROVIDER_ENABLED;

gc_heap_dump_mem_block_free_all ();

gc_heap_dump_request_params_free ();
provider_params_free ();

ep_rt_spin_lock_free (&_gc_lock);

// We were cleaning up resources (mutexes, tls data, etc) here but it races with
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
// and not leaking these threads becomes a priority we will have to reimplement
// cleanup here.
}
}

Expand Down
32 changes: 4 additions & 28 deletions src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -4630,26 +4630,10 @@ ep_rt_mono_runtime_provider_init (void)
void
ep_rt_mono_runtime_provider_fini (void)
{
if (_sampled_thread_callstacks)
g_array_free (_sampled_thread_callstacks, TRUE);
_sampled_thread_callstacks = NULL;

_max_sampled_thread_count = 32;

g_free (_runtime_helper_compile_method_jitinfo);
_runtime_helper_compile_method_jitinfo = NULL;

if (_runtime_helper_compile_method)
mono_free_method (_runtime_helper_compile_method);
_runtime_helper_compile_method = NULL;

g_free (_monitor_enter_method_jitinfo);
_monitor_enter_method_jitinfo = NULL;
_monitor_enter_method = NULL;

g_free (_monitor_enter_v4_method_jitinfo);
_monitor_enter_v4_method_jitinfo = NULL;
_monitor_enter_v4_method = NULL;
// We were cleaning up resources (mutexes, tls data, etc) here but it races with
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
// and not leaking these threads becomes a priority we will have to reimplement
// cleanup here.

if (_ep_rt_mono_default_profiler_provider) {
mono_profiler_set_jit_begin_callback (_ep_rt_mono_default_profiler_provider, NULL);
Expand Down Expand Up @@ -4680,14 +4664,6 @@ ep_rt_mono_runtime_provider_fini (void)
_gc_heap_dump_requests = 0;
_gc_heap_dump_count = 0;
_gc_heap_dump_trigger_count = 0;

dn_vector_dispose (&_gc_heap_dump_requests_data);
memset (&_gc_heap_dump_requests_data, 0, sizeof (_gc_heap_dump_requests_data));

dn_umap_dispose (&_gc_roots_table);
memset (&_gc_roots_table, 0, sizeof (_gc_roots_table));

ep_rt_spin_lock_free (&_gc_lock);
}

void
Expand Down
35 changes: 5 additions & 30 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,44 +852,19 @@ ep_rt_mono_init_finish (void)
void
ep_rt_mono_fini (void)
{
// Avoid cleaning up resources to prevent cleaning up out from under running
// threads.
if (!mono_runtime_is_shutting_down ())
return;

ep_rt_mono_runtime_provider_fini ();
ep_rt_mono_profiler_provider_fini ();

if (_eventpipe_initialized)
mono_rand_close (_rand_provider);

_rand_provider = NULL;
_eventpipe_initialized = FALSE;

_ep_rt_mono_runtime_initialized = FALSE;

if (_ep_rt_mono_default_profiler_provider) {
mono_profiler_set_runtime_initialized_callback (_ep_rt_mono_default_profiler_provider, NULL);
mono_profiler_set_thread_started_callback (_ep_rt_mono_default_profiler_provider, NULL);
mono_profiler_set_thread_stopped_callback (_ep_rt_mono_default_profiler_provider, NULL);
}
_ep_rt_mono_default_profiler_provider = NULL;

if (_ep_rt_mono_thread_holder_tls_id)
mono_native_tls_free (_ep_rt_mono_thread_holder_tls_id);
_ep_rt_mono_thread_holder_tls_id = 0;

if (_thread_data_tls_id)
mono_native_tls_free (_thread_data_tls_id);
_thread_data_tls_id = 0;

_ep_rt_mono_os_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
_ep_rt_mono_os_cmd_line = NULL;

_ep_rt_mono_managed_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
_ep_rt_mono_managed_cmd_line = NULL;

ep_rt_spin_lock_free (&_ep_rt_mono_config_lock);

// We were cleaning up resources (mutexes, tls data, etc) here but it races with
// other threads on shutdown. Skipping cleanup to prevent failures. If unloading
// and not leaking these threads becomes a priority we will have to reimplement
// cleanup here.
}

void
Expand Down

0 comments on commit 4e702bc

Please sign in to comment.