Commit 08e32230 authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Make our FIDL error-handlers more consistent.

Update the functions we register as FIDL error handlers to use :
- ZX_LOG(FATAL, status) where we never expect to lose connectivity,
  e.g. for connections to system services such as the Netstack. We
  typically follow these with an indication of what disconnected, e.g:
    ZX_LOG(FATAL, status) << " Netstack disconnected.";
- ZX_LOG_IF(FATAL, status != ZX_ERR_PEER_CLOSED, status) where we are
  providing service to a single peer that may disconnect from us at any
  time, where other status values are unexpected.
- ZX_LOG(ERROR, status) where we never expect to lose connectivity, but
  are serving multiple peers, so must not simply crash the process.
- ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status) where we are
  providing service to multiple peers that we expect may disconnect, to
  verify that they do so gracefully.

We also update FIDL error handlers in some test suites:
- EXPECT_EQ(status, ZX_ERR_PEER_CLOSED) where the test actively expects
  that the FIDL channel will be disconnected gracefully.
- ZX_LOG(ERROR, status) where the test does not expect FIDL errors.

Bug: 927400
Change-Id: I10fef90778e58f2aedadb806f857da00aace96aa
Reviewed-on: https://chromium-review.googlesource.com/c/1448796
Auto-Submit: Wez <wez@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628524}
parent 86f2d703
...@@ -191,8 +191,11 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents, ...@@ -191,8 +191,11 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
binding_(this, std::move(frame_request)) { binding_(this, std::move(frame_request)) {
web_contents_->SetDelegate(this); web_contents_->SetDelegate(this);
Observe(web_contents_.get()); Observe(web_contents_.get());
binding_.set_error_handler( binding_.set_error_handler([this](zx_status_t status) {
[this](zx_status_t status) { context_->DestroyFrame(this); }); ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
<< " Frame disconnected.";
context_->DestroyFrame(this);
});
content::UpdateFontRendererPreferencesFromSystemSettings( content::UpdateFontRendererPreferencesFromSystemSettings(
web_contents_->GetMutableRendererPrefs()); web_contents_->GetMutableRendererPrefs());
......
...@@ -152,7 +152,10 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, ContextDeletedBeforeFrame) { ...@@ -152,7 +152,10 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, ContextDeletedBeforeFrame) {
EXPECT_TRUE(frame); EXPECT_TRUE(frame);
base::RunLoop run_loop; base::RunLoop run_loop;
frame.set_error_handler([&run_loop](zx_status_t status) { run_loop.Quit(); }); frame.set_error_handler([&run_loop](zx_status_t status) {
EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
context().Unbind(); context().Unbind();
run_loop.Run(); run_loop.Run();
EXPECT_FALSE(frame); EXPECT_FALSE(frame);
......
...@@ -113,8 +113,8 @@ MessagePortImpl::MessagePortImpl(mojo::ScopedMessagePipeHandle mojo_port) ...@@ -113,8 +113,8 @@ MessagePortImpl::MessagePortImpl(mojo::ScopedMessagePipeHandle mojo_port)
connector_->set_connection_error_handler( connector_->set_connection_error_handler(
base::BindOnce(&MessagePortImpl::OnDisconnected, base::Unretained(this))); base::BindOnce(&MessagePortImpl::OnDisconnected, base::Unretained(this)));
binding_.set_error_handler([this](zx_status_t status) { binding_.set_error_handler([this](zx_status_t status) {
if (status != ZX_OK && status != ZX_ERR_PEER_CLOSED) ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
ZX_DLOG(INFO, status) << "Disconnected"; << " MessagePort disconnected.";
OnDisconnected(); OnDisconnected();
}); });
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "fuchsia/browser/context_impl.h" #include "fuchsia/browser/context_impl.h"
#include "fuchsia/browser/webrunner_browser_context.h" #include "fuchsia/browser/webrunner_browser_context.h"
...@@ -52,7 +54,8 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() { ...@@ -52,7 +54,8 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
// Quit the browser main loop when the Context connection is dropped. // Quit the browser main loop when the Context connection is dropped.
context_binding_->set_error_handler([this](zx_status_t status) { context_binding_->set_error_handler([this](zx_status_t status) {
DLOG(WARNING) << "Client connection to Context service dropped."; ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
<< " Context disconnected.";
context_service_.reset(); context_service_.reset();
std::move(quit_closure_).Run(); std::move(quit_closure_).Run();
}); });
......
...@@ -111,7 +111,8 @@ IN_PROC_BROWSER_TEST_F(NamedMessagePortConnectorTest, ...@@ -111,7 +111,8 @@ IN_PROC_BROWSER_TEST_F(NamedMessagePortConnectorTest,
// Ensure that the MessagePort is dropped when navigating away. // Ensure that the MessagePort is dropped when navigating away.
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
(*message_port).set_error_handler([&run_loop](zx_status_t) { (*message_port).set_error_handler([&run_loop](zx_status_t status) {
EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
run_loop.Quit(); run_loop.Quit();
}); });
controller->LoadUrl("about:blank", nullptr); controller->LoadUrl("about:blank", nullptr);
......
...@@ -122,7 +122,11 @@ URLLoaderImpl::URLLoaderImpl(std::unique_ptr<net::URLRequestContext> context, ...@@ -122,7 +122,11 @@ URLLoaderImpl::URLLoaderImpl(std::unique_ptr<net::URLRequestContext> context,
context_(std::move(context)), context_(std::move(context)),
buffer_(new net::GrowableIOBuffer()), buffer_(new net::GrowableIOBuffer()),
write_watch_(FROM_HERE) { write_watch_(FROM_HERE) {
binding_.set_error_handler([this](zx_status_t status) { delete this; }); binding_.set_error_handler([this](zx_status_t status) {
ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
<< " URLLoader disconnected.";
delete this;
});
g_active_requests++; g_active_requests++;
} }
......
...@@ -35,7 +35,7 @@ CastChannelBindings::CastChannelBindings( ...@@ -35,7 +35,7 @@ CastChannelBindings::CastChannelBindings(
DCHECK(frame_); DCHECK(frame_);
channel_consumer_.set_error_handler([this](zx_status_t status) mutable { channel_consumer_.set_error_handler([this](zx_status_t status) mutable {
ZX_LOG(ERROR, status) << "CastChannel error:"; ZX_LOG(ERROR, status) << " Agent disconnected.";
std::move(on_error_closure_).Run(); std::move(on_error_closure_).Run();
}); });
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <lib/fit/function.h> #include <lib/fit/function.h>
#include <utility> #include <utility>
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h" #include "base/fuchsia/service_directory.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -57,7 +58,10 @@ WebComponent::WebComponent( ...@@ -57,7 +58,10 @@ WebComponent::WebComponent(
if (controller_request.is_valid()) { if (controller_request.is_valid()) {
controller_binding_.Bind(std::move(controller_request)); controller_binding_.Bind(std::move(controller_request));
controller_binding_.set_error_handler([this](zx_status_t status) { controller_binding_.set_error_handler([this](zx_status_t status) {
// Signal graceful process termination. ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
<< " ComponentController disconnected.";
// Teardown the component with dummy values, since ComponentController
// channel isn't there to receive them.
DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED); DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED);
}); });
} }
......
...@@ -82,8 +82,10 @@ MULTIPROCESS_TEST_MAIN(SpawnContextServer) { ...@@ -82,8 +82,10 @@ MULTIPROCESS_TEST_MAIN(SpawnContextServer) {
// Quit the process when the context is destroyed. // Quit the process when the context is destroyed.
base::RunLoop run_loop; base::RunLoop run_loop;
context_binding.set_error_handler( context_binding.set_error_handler([&run_loop](zx_status_t status) {
[&run_loop](zx_status_t status) { run_loop.Quit(); }); EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
run_loop.Run(); run_loop.Run();
return 0; return 0;
...@@ -111,12 +113,14 @@ class ContextProviderImplTest : public base::MultiProcessTest { ...@@ -111,12 +113,14 @@ class ContextProviderImplTest : public base::MultiProcessTest {
// Call a Context method and wait for it to invoke an observer call. // Call a Context method and wait for it to invoke an observer call.
base::RunLoop run_loop; base::RunLoop run_loop;
context->set_error_handler([&run_loop](zx_status_t status) { context->set_error_handler([&run_loop](zx_status_t status) {
ZX_LOG(ERROR, status) << " Context lost.";
ADD_FAILURE(); ADD_FAILURE();
run_loop.Quit(); run_loop.Quit();
}); });
chromium::web::FramePtr frame_ptr; chromium::web::FramePtr frame_ptr;
frame_ptr.set_error_handler([&run_loop](zx_status_t status) { frame_ptr.set_error_handler([&run_loop](zx_status_t status) {
ZX_LOG(ERROR, status) << " Frame lost.";
ADD_FAILURE(); ADD_FAILURE();
run_loop.Quit(); run_loop.Quit();
}); });
...@@ -151,8 +155,10 @@ class ContextProviderImplTest : public base::MultiProcessTest { ...@@ -151,8 +155,10 @@ class ContextProviderImplTest : public base::MultiProcessTest {
void CheckContextUnresponsive( void CheckContextUnresponsive(
fidl::InterfacePtr<chromium::web::Context>* context) { fidl::InterfacePtr<chromium::web::Context>* context) {
base::RunLoop run_loop; base::RunLoop run_loop;
context->set_error_handler( context->set_error_handler([&run_loop](zx_status_t status) {
[&run_loop](zx_status_t status) { run_loop.Quit(); }); EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
run_loop.Quit();
});
chromium::web::FramePtr frame; chromium::web::FramePtr frame;
(*context)->CreateFrame(frame.NewRequest()); (*context)->CreateFrame(frame.NewRequest());
......
...@@ -4,13 +4,17 @@ ...@@ -4,13 +4,17 @@
#include "fuchsia/test/fake_context.h" #include "fuchsia/test/fake_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h" #include "base/logging.h"
namespace webrunner { namespace webrunner {
FakeFrame::FakeFrame(fidl::InterfaceRequest<chromium::web::Frame> request) FakeFrame::FakeFrame(fidl::InterfaceRequest<chromium::web::Frame> request)
: binding_(this, std::move(request)) { : binding_(this, std::move(request)) {
binding_.set_error_handler([this](zx_status_t status) { delete this; }); binding_.set_error_handler([this](zx_status_t status) {
ZX_CHECK(status == ZX_ERR_PEER_CLOSED, status);
delete this;
});
} }
FakeFrame::~FakeFrame() = default; FakeFrame::~FakeFrame() = default;
......
...@@ -52,7 +52,7 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia( ...@@ -52,7 +52,7 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
DCHECK(netstack_); DCHECK(netstack_);
netstack_.set_error_handler([](zx_status_t status) { netstack_.set_error_handler([](zx_status_t status) {
ZX_LOG(ERROR, status) << "Lost connection to netstack."; ZX_LOG(FATAL, status) << "Lost connection to netstack.";
}); });
netstack_.events().OnInterfacesChanged = netstack_.events().OnInterfacesChanged =
[this](std::vector<fuchsia::netstack::NetInterface> interfaces) { [this](std::vector<fuchsia::netstack::NetInterface> interfaces) {
......
...@@ -20,13 +20,8 @@ InputMethodKeyboardControllerFuchsia::InputMethodKeyboardControllerFuchsia( ...@@ -20,13 +20,8 @@ InputMethodKeyboardControllerFuchsia::InputMethodKeyboardControllerFuchsia(
->ConnectToService<fuchsia::ui::input::ImeVisibilityService>()) { ->ConnectToService<fuchsia::ui::input::ImeVisibilityService>()) {
DCHECK(ime_service_); DCHECK(ime_service_);
ime_visibility_.set_error_handler([this](zx_status_t status) { ime_visibility_.set_error_handler([](zx_status_t status) {
ZX_LOG(WARNING, status) << "ImeVisibilityService connection lost."; ZX_LOG(FATAL, status) << " ImeVisibilityService lost.";
// We can't observe visibility events anymore, so dismiss the keyboard and
// assume that it's closed for good.
DismissVirtualKeyboard();
keyboard_visible_ = false;
}); });
ime_visibility_.events().OnKeyboardVisibilityChanged = [this](bool visible) { ime_visibility_.events().OnKeyboardVisibilityChanged = [this](bool visible) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/ozone/platform/scenic/scenic_window_manager.h" #include "ui/ozone/platform/scenic/scenic_window_manager.h"
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "ui/ozone/platform/scenic/ozone_platform_scenic.h" #include "ui/ozone/platform/scenic/ozone_platform_scenic.h"
namespace ui { namespace ui {
...@@ -24,9 +25,7 @@ fuchsia::ui::viewsv1::ViewManager* ScenicWindowManager::GetViewManager() { ...@@ -24,9 +25,7 @@ fuchsia::ui::viewsv1::ViewManager* ScenicWindowManager::GetViewManager() {
view_manager_ = base::fuchsia::ComponentContext::GetDefault() view_manager_ = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::viewsv1::ViewManager>(); ->ConnectToService<fuchsia::ui::viewsv1::ViewManager>();
view_manager_.set_error_handler([](zx_status_t status) { view_manager_.set_error_handler([](zx_status_t status) {
LOG(ERROR) ZX_LOG(FATAL, status) << " ViewManager lost.";
<< "The ViewManager channel was unexpectedly terminated with status "
<< status << ".";
}); });
} }
...@@ -37,9 +36,8 @@ fuchsia::ui::scenic::Scenic* ScenicWindowManager::GetScenic() { ...@@ -37,9 +36,8 @@ fuchsia::ui::scenic::Scenic* ScenicWindowManager::GetScenic() {
if (!scenic_) { if (!scenic_) {
scenic_ = base::fuchsia::ComponentContext::GetDefault() scenic_ = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::scenic::Scenic>(); ->ConnectToService<fuchsia::ui::scenic::Scenic>();
scenic_.set_error_handler([](zx_status_t status) { scenic_.set_error_handler(
LOG(ERROR) << "The Scenic channel was unexpectedly terminated."; [](zx_status_t status) { ZX_LOG(FATAL, status) << " Scenic lost."; });
});
} }
return scenic_.get(); return scenic_.get();
} }
......
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