Commit 0df4474a authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[Watch flakes]: Fix flakes from NetworkChangeNotifier

By default, the NetworkService bootstraps a leaking
SystemDnsConfigChangeNotifier singleton object in
NetworkChangeNotifier::NetworkChangeNotifier().

This SystemDnsConfigChangeNotifier observes the DNS configuration (via
FilePathWatchers on /etc/resolv.conf and /etc/hosts on POSIX and via
ObjectWatchers on the registry on Windows). These watchers outlive the
BrowserTaskEnvironment of the RenderViewHostTestHarness, including it's message
queues.

If the trybots experience network changes (e.g. due to expiring DHCP leases or
other problems), it is possible that the watchers post messages to a message
queue that has been destroyed already, see crbug.com/1011275#c3.

This CL cause NetworkService to use a mock NetworkChangeNotifier
which does not observe network changes.

Bug: 1011275
Change-Id: I426999899cadf4732a93d4040871f56332422d4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856803Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarEric Orth <ericorth@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706449}
parent 0175a57f
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "services/network/public/mojom/net_log.mojom.h" #include "services/network/public/mojom/net_log.mojom.h"
#include "services/network/public/mojom/network_change_manager.mojom.h" #include "services/network/public/mojom/network_change_manager.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/network_service_test.mojom.h" #include "services/network/public/mojom/network_service_test.mojom.h"
namespace content { namespace content {
...@@ -162,8 +163,12 @@ void CreateNetworkServiceOnIOForTesting( ...@@ -162,8 +163,12 @@ void CreateNetworkServiceOnIOForTesting(
return; return;
} }
GetLocalNetworkService() = GetLocalNetworkService() = std::make_unique<network::NetworkService>(
std::make_unique<network::NetworkService>(nullptr, std::move(receiver)); nullptr /* registry */, std::move(receiver),
true /* delay_initialization_until_set_client */);
GetLocalNetworkService()->Initialize(
network::mojom::NetworkServiceParams::New(),
true /* mock_network_change_notifier */);
if (completion_event) if (completion_event)
completion_event->Signal(); completion_event->Signal();
} }
......
...@@ -92,10 +92,13 @@ constexpr auto kUpdateLoadStatesInterval = ...@@ -92,10 +92,13 @@ constexpr auto kUpdateLoadStatesInterval =
std::unique_ptr<net::NetworkChangeNotifier> CreateNetworkChangeNotifierIfNeeded( std::unique_ptr<net::NetworkChangeNotifier> CreateNetworkChangeNotifierIfNeeded(
net::NetworkChangeNotifier::ConnectionType initial_connection_type, net::NetworkChangeNotifier::ConnectionType initial_connection_type,
net::NetworkChangeNotifier::ConnectionSubtype initial_connection_subtype) { net::NetworkChangeNotifier::ConnectionSubtype initial_connection_subtype,
bool mock_network_change_notifier) {
// There is a global singleton net::NetworkChangeNotifier if NetworkService // There is a global singleton net::NetworkChangeNotifier if NetworkService
// is running inside of the browser process. // is running inside of the browser process.
if (!net::NetworkChangeNotifier::HasNetworkChangeNotifier()) { if (!net::NetworkChangeNotifier::HasNetworkChangeNotifier()) {
if (mock_network_change_notifier)
return net::NetworkChangeNotifier::CreateMock();
#if defined(OS_ANDROID) || defined(OS_CHROMEOS) #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
// On Android and ChromeOS, network change events are synced from the // On Android and ChromeOS, network change events are synced from the
// browser process. // browser process.
...@@ -227,7 +230,8 @@ NetworkService::NetworkService( ...@@ -227,7 +230,8 @@ NetworkService::NetworkService(
Initialize(mojom::NetworkServiceParams::New()); Initialize(mojom::NetworkServiceParams::New());
} }
void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params) { void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params,
bool mock_network_change_notifier) {
if (initialized_) if (initialized_)
return; return;
...@@ -268,7 +272,8 @@ void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params) { ...@@ -268,7 +272,8 @@ void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params) {
net::NetworkChangeNotifier::ConnectionType( net::NetworkChangeNotifier::ConnectionType(
params->initial_connection_type), params->initial_connection_type),
net::NetworkChangeNotifier::ConnectionSubtype( net::NetworkChangeNotifier::ConnectionSubtype(
params->initial_connection_subtype))); params->initial_connection_subtype),
mock_network_change_notifier));
trace_net_log_observer_.WatchForTraceStart(net_log_); trace_net_log_observer_.WatchForTraceStart(net_log_);
......
...@@ -79,7 +79,8 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService ...@@ -79,7 +79,8 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService
// Allows the browser process to synchronously initialize the NetworkService. // Allows the browser process to synchronously initialize the NetworkService.
// TODO(jam): remove this once the old path is gone. // TODO(jam): remove this once the old path is gone.
void Initialize(mojom::NetworkServiceParamsPtr params); void Initialize(mojom::NetworkServiceParamsPtr params,
bool mock_network_change_notifier = false);
// Creates a NetworkService instance on the current thread. // Creates a NetworkService instance on the current thread.
static std::unique_ptr<NetworkService> Create( static std::unique_ptr<NetworkService> Create(
......
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