Commit 05d86531 authored by James Vecore's avatar James Vecore Committed by Commit Bot

[Nearby] Use SharedRemote in Bluetooth Socket

Previously, the socket's remote was bound on a different thread from
the one that would eventually call Disconnect which was causing a
deadlock when Nearby Connections was cleaning up a channel.

By switching to a shared remote that is explicitly bound on the task
runner we avoid the deadlock with minimal changes.

Fixed: 1132738
Change-Id: I19f89d5f38cc6ae88237038aa3cc0cc6e3eb8f5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437689
Auto-Submit: James Vecore <vecore@google.com>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#812255}
parent e0987ee4
...@@ -257,8 +257,9 @@ BluetoothSocket::BluetoothSocket( ...@@ -257,8 +257,9 @@ BluetoothSocket::BluetoothSocket(
mojo::ScopedDataPipeProducerHandle send_stream) mojo::ScopedDataPipeProducerHandle send_stream)
: remote_device_(std::move(device)), : remote_device_(std::move(device)),
remote_device_ref_(*remote_device_), remote_device_ref_(*remote_device_),
task_runner_(base::ThreadPool::CreateSequencedTaskRunner({})), task_runner_(
socket_(std::move(socket)) { base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})),
socket_(std::move(socket), task_runner_) {
InitializeStreams(std::move(receive_stream), std::move(send_stream)); InitializeStreams(std::move(receive_stream), std::move(send_stream));
} }
...@@ -268,8 +269,9 @@ BluetoothSocket::BluetoothSocket( ...@@ -268,8 +269,9 @@ BluetoothSocket::BluetoothSocket(
mojo::ScopedDataPipeConsumerHandle receive_stream, mojo::ScopedDataPipeConsumerHandle receive_stream,
mojo::ScopedDataPipeProducerHandle send_stream) mojo::ScopedDataPipeProducerHandle send_stream)
: remote_device_ref_(remote_device), : remote_device_ref_(remote_device),
task_runner_(base::ThreadPool::CreateSequencedTaskRunner({})), task_runner_(
socket_(std::move(socket)) { base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})),
socket_(std::move(socket), task_runner_) {
InitializeStreams(std::move(receive_stream), std::move(send_stream)); InitializeStreams(std::move(receive_stream), std::move(send_stream));
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "chrome/services/sharing/nearby/platform_v2/bluetooth_device.h" #include "chrome/services/sharing/nearby/platform_v2/bluetooth_device.h"
#include "device/bluetooth/public/mojom/adapter.mojom.h" #include "device/bluetooth/public/mojom/adapter.mojom.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/shared_remote.h"
#include "third_party/nearby/src/cpp/platform_v2/api/bluetooth_classic.h" #include "third_party/nearby/src/cpp/platform_v2/api/bluetooth_classic.h"
#include "third_party/nearby/src/cpp/platform_v2/base/input_stream.h" #include "third_party/nearby/src/cpp/platform_v2/base/input_stream.h"
#include "third_party/nearby/src/cpp/platform_v2/base/output_stream.h" #include "third_party/nearby/src/cpp/platform_v2/base/output_stream.h"
...@@ -105,7 +105,7 @@ class BluetoothSocket : public api::BluetoothSocket { ...@@ -105,7 +105,7 @@ class BluetoothSocket : public api::BluetoothSocket {
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
// These properties must be created on |task_runner_|. See |task_runner_|. // These properties must be created on |task_runner_|. See |task_runner_|.
mojo::Remote<bluetooth::mojom::Socket> socket_; mojo::SharedRemote<bluetooth::mojom::Socket> socket_;
std::unique_ptr<InputStream> input_stream_; std::unique_ptr<InputStream> input_stream_;
std::unique_ptr<OutputStream> output_stream_; std::unique_ptr<OutputStream> output_stream_;
}; };
......
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