Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2160)

Unified Diff: base/trace_event/memory_dump_manager.cc

Issue 1884573002: Fix race condition when dump providers invoked within destroyed state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/memory_dump_manager.cc
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index 35b27d9a03a0a0212b0f807e83068881f3d4395b..53532b231242ff567e07486f680c1819cf6bb092 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -407,8 +407,14 @@ void MemoryDumpManager::SetupNextMemoryDump(
// (for discounting trace memory overhead) while holding the |lock_|.
TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported();
- // If this was the last hop, create a trace event, add it to the trace and
- // finalize process dump (invoke callback).
+ // |dump_thread_| might be destroyed before getting this point.
+ // It means that tracing was disabled right before starting this dump.
+ // Anyway either tracing is stopped or this was the last hop, create a trace
+ // event, add it to the trace and finalize process dump invoking the callback.
+ if (!pmd_async_state->dump_thread_task_runner.get()) {
+ pmd_async_state->dump_successful = false;
+ pmd_async_state->pending_dump_providers.clear();
+ }
if (pmd_async_state->pending_dump_providers.empty())
return FinalizeDumpAndAddToTrace(std::move(pmd_async_state));
@@ -418,20 +424,12 @@ void MemoryDumpManager::SetupNextMemoryDump(
pmd_async_state->pending_dump_providers.back().get();
// If the dump provider did not specify a task runner affinity, dump on
- // |dump_thread_|. Note that |dump_thread_| might have been destroyed
- // meanwhile.
+ // |dump_thread_| which is already checked above for presence.
SequencedTaskRunner* task_runner = mdpinfo->task_runner.get();
if (!task_runner) {
DCHECK(mdpinfo->options.dumps_on_single_thread_task_runner);
task_runner = pmd_async_state->dump_thread_task_runner.get();
- if (!task_runner) {
- // If tracing was disabled before reaching CreateProcessDump() the
- // dump_thread_ would have been already torn down. Nack current dump and
- // continue.
- pmd_async_state->dump_successful = false;
- pmd_async_state->pending_dump_providers.pop_back();
- return SetupNextMemoryDump(std::move(pmd_async_state));
- }
+ DCHECK(task_runner);
}
if (mdpinfo->options.dumps_on_single_thread_task_runner &&
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698