Reset Daemon-owned AssociatedReceiver when worker process exits
We've seen a number of crashes in our Windows host where the daemon
process instructs the remoting_desktop process to crash, based on the
memory dumps available, it looks like this is because remoting_desktop
is requesting an associated interface when the receiver was already
bound.
I don't have the exact repro steps but I can approximate this by
using task manager and killing the remoting_desktop.exe. The daemon
process will spin up a new remoting_desktop instance which then
requests the bound interface which isn't allowed.
This CL unbinds the associated receiver when the worker process has
exited (and before the worker process launcher spins up a new instance).
I wanted to manage the associated receiver's state so that it was
in sync with the states reported by the worker process lanucher.
Bug: 1265449
Change-Id: I237bc85736d0c1990b54e8da68784f12bcb3a224
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3257460
Reviewed-by: Yuwei Huang <[email protected]>
Commit-Queue: Joe Downing <[email protected]>
Cr-Commit-Position: refs/heads/main@{#937582}
diff --git a/remoting/host/desktop_session_win.cc b/remoting/host/desktop_session_win.cc
index 0ba25b2..411bae00 100644
--- a/remoting/host/desktop_session_win.cc
+++ b/remoting/host/desktop_session_win.cc
@@ -746,6 +746,14 @@
mojo::PendingAssociatedReceiver<mojom::DesktopSessionRequestHandler>
pending_receiver(std::move(handle));
desktop_session_request_handler_.Bind(std::move(pending_receiver));
+
+ // Set up a disconnect handler so |desktop_session_request_handler_| can be
+ // re-bound if |launcher_| spawns a new desktop process.
+ // TODO(joedow): Add a reset_on_disconnect() method on associated receiver.
+ desktop_session_request_handler_.set_disconnect_handler(base::BindOnce(
+ [](mojo::AssociatedReceiver<mojom::DesktopSessionRequestHandler>*
+ receiver) { receiver->reset(); },
+ base::Unretained(&desktop_session_request_handler_)));
} else {
LOG(ERROR) << "Unknown associated interface requested: " << interface_name
<< ", crashing the desktop process";