Commit 80c28b87 authored by Alex Clarke's avatar Alex Clarke Committed by Commit Bot

Fix ThreadTaskRunnerHandle::Get calls during SequenceManager destruction

Some PostTask closures do exciting things on destruction like posting
other tasks. Some of them call ThreadTaskRunnerHandle::Get and these where
crashing because it had gone away.  This patch fixes that.

Bug: 933295
Change-Id: I7f48e2743dcebe38f9f6e9f08030d762760fc733
Reviewed-on: https://chromium-review.googlesource.com/c/1482954Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634649}
parent 0ada45d2
......@@ -129,15 +129,15 @@ SequenceManagerImpl::~SequenceManagerImpl() {
DCHECK(!controller_->GetBoundMessagePump() ||
main_thread_only().task_execution_stack.empty());
// TODO(altimin): restore default task runner automatically when
// ThreadController is destroyed.
controller_->RestoreDefaultTaskRunner();
for (internal::TaskQueueImpl* queue : main_thread_only().active_queues) {
main_thread_only().selector.RemoveQueue(queue);
queue->UnregisterTaskQueue();
}
// TODO(altimin): restore default task runner automatically when
// ThreadController is destroyed.
controller_->RestoreDefaultTaskRunner();
main_thread_only().active_queues.clear();
main_thread_only().queues_to_gracefully_shutdown.clear();
main_thread_only().selector.SetTaskQueueSelectorObserver(nullptr);
......
......@@ -3920,6 +3920,21 @@ TEST_P(SequenceManagerTest, DestructorPostChainDuringShutdown) {
EXPECT_TRUE(run);
}
TEST_P(SequenceManagerTest, DestructorPostsViaTaskRunnerHandleDuringShutdown) {
scoped_refptr<TestTaskQueue> task_queue = CreateTaskQueue();
bool run = false;
task_queue->task_runner()->PostTask(
FROM_HERE, RunOnDestruction(BindLambdaForTesting([&]() {
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::BindOnce(&NopTask));
run = true;
})));
// Should not DCHECK when ThreadTaskRunnerHandle::Get() is invoked.
DestroySequenceManager();
EXPECT_TRUE(run);
}
TEST_P(SequenceManagerTest, CreateUnboundSequenceManagerWhichIsNeverBound) {
// This should not crash.
CreateUnboundSequenceManager();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment