Commit 3b633001 authored by Yuzu Saijo's avatar Yuzu Saijo Committed by Commit Bot

Fix std::map usage in IPC GetTaskRunner

This CL fixes the incorrect usage of std::map.

The lookup in the map is using the [] operator which is creating a
default entry when the key is not present.

etienne@ first tried to land this fix but had to revert because some
tests became flaky (which was supposed to happen when we first
associated IPCs with per-frame task runners here
https://chromium-review.googlesource.com/c/chromium/src/+/1526067 ,
but was hidden because of this bug).
Test failure example:
https://ci.chromium.org/p/chromium/builders/ci/Linux%20ChromiumOS%20MSan%20Tests/13652

This is a second try to fix the incorrect map usage.

-- update --

The flaky tests were because of scheduling experiments that set the
background tasks to low priority, and this fix just surfaced the
issue because now tasks are posted to per-frame task runners.
CL to disable the experiments:
https://chromium-review.googlesource.com/c/chromium/src/+/1692577

Now that the experiments are disabled, this memory leak fix should
not make the tests flaky any more.

Bug: 973200, 980523
Change-Id: I1eaf0af67f1bcbd582a510d70174666251b8b4ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686979
Commit-Queue: Yuzu Saijo <yuzus@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676283}
parent c22c65b5
...@@ -345,23 +345,22 @@ void ChannelProxy::Context::AddListenerTaskRunner( ...@@ -345,23 +345,22 @@ void ChannelProxy::Context::AddListenerTaskRunner(
void ChannelProxy::Context::RemoveListenerTaskRunner(int32_t routing_id) { void ChannelProxy::Context::RemoveListenerTaskRunner(int32_t routing_id) {
DCHECK(default_listener_task_runner_->BelongsToCurrentThread()); DCHECK(default_listener_task_runner_->BelongsToCurrentThread());
base::AutoLock lock(listener_thread_task_runners_lock_); base::AutoLock lock(listener_thread_task_runners_lock_);
if (base::Contains(listener_thread_task_runners_, routing_id)) listener_thread_task_runners_.erase(routing_id);
listener_thread_task_runners_.erase(routing_id);
} }
// Called on the IPC::Channel thread. // Called on the IPC::Channel thread.
base::SingleThreadTaskRunner* ChannelProxy::Context::GetTaskRunner( scoped_refptr<base::SingleThreadTaskRunner>
int32_t routing_id) { ChannelProxy::Context::GetTaskRunner(int32_t routing_id) {
DCHECK(ipc_task_runner_->BelongsToCurrentThread()); DCHECK(ipc_task_runner_->BelongsToCurrentThread());
if (routing_id == MSG_ROUTING_NONE) if (routing_id == MSG_ROUTING_NONE)
return default_listener_task_runner_.get(); return default_listener_task_runner_;
base::AutoLock lock(listener_thread_task_runners_lock_); base::AutoLock lock(listener_thread_task_runners_lock_);
base::SingleThreadTaskRunner* task_runner = auto task_runner = listener_thread_task_runners_.find(routing_id);
listener_thread_task_runners_[routing_id].get(); if (task_runner == listener_thread_task_runners_.end())
if (task_runner) return default_listener_task_runner_;
return task_runner; DCHECK(task_runner->second);
return default_listener_task_runner_.get(); return task_runner->second;
} }
// Called on the listener's thread // Called on the listener's thread
......
...@@ -282,7 +282,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender { ...@@ -282,7 +282,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender {
// Called on the IPC::Channel thread. // Called on the IPC::Channel thread.
// Returns the task runner associated with |routing_id|. // Returns the task runner associated with |routing_id|.
base::SingleThreadTaskRunner* GetTaskRunner(int32_t routing_id); scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
int32_t routing_id);
protected: protected:
friend class base::RefCountedThreadSafe<Context>; friend class base::RefCountedThreadSafe<Context>;
......
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