Commit f138284b authored by Tiansong Cui's avatar Tiansong Cui Committed by Commit Bot

[Chromecast][BLE] Fix crash caused by command complete callback after disconnect

We might receive command complete callbacks after device is disconnected.
Because we have already cleared the command queue, this will result in
DCHECK fail in eng builds or segmentation fault in user builds.
We fix this issue and avoid device crash in this case.

Bug: internal b/135691184
Test: cast_bluetooth_unittests, manual
Change-Id: Ic086f56734fa20e836341768bfe7c3187de92fe0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1673084
Auto-Submit: Tiansong Cui <tiansong@google.com>
Commit-Queue: Yuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671547}
parent 70c6cdc6
...@@ -545,7 +545,10 @@ void RemoteDeviceImpl::EnqueueOperation(const std::string& name, ...@@ -545,7 +545,10 @@ void RemoteDeviceImpl::EnqueueOperation(const std::string& name,
void RemoteDeviceImpl::NotifyQueueOperationComplete() { void RemoteDeviceImpl::NotifyQueueOperationComplete() {
DCHECK(io_task_runner_->BelongsToCurrentThread()); DCHECK(io_task_runner_->BelongsToCurrentThread());
DCHECK(!command_queue_.empty()); if (command_queue_.empty()) {
LOG(ERROR) << "Command queue is empty, device might be disconnected";
return;
}
command_queue_.pop_front(); command_queue_.pop_front();
command_timeout_timer_.Stop(); command_timeout_timer_.Stop();
...@@ -557,7 +560,10 @@ void RemoteDeviceImpl::NotifyQueueOperationComplete() { ...@@ -557,7 +560,10 @@ void RemoteDeviceImpl::NotifyQueueOperationComplete() {
void RemoteDeviceImpl::RunNextOperation() { void RemoteDeviceImpl::RunNextOperation() {
DCHECK(io_task_runner_->BelongsToCurrentThread()); DCHECK(io_task_runner_->BelongsToCurrentThread());
DCHECK(!command_queue_.empty()); if (command_queue_.empty()) {
LOG(ERROR) << "Command queue is empty, device might be disconnected";
return;
}
auto& front = command_queue_.front(); auto& front = command_queue_.front();
command_timeout_timer_.Start( command_timeout_timer_.Start(
FROM_HERE, kCommandTimeout, FROM_HERE, kCommandTimeout,
......
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