Revert "adb: fix deadlock between transport_unref and usb_close."
This reverts commit e44e98355bf9ee5a87469ce66b2800913a97cfe4.
The mutex lock in transport_unref hides a race that seems otherwise
hard to fix. Specifically, there's no synchronization between acquiring
a transport and attaching it to an asocket*, leading to badness if the
transport is closed in between the two operations.
Fix the original problem the reverted patch addressed by manually
unlocking before calling unregister_usb_transport.
Bug: http://b/65419665
Test: python test_device.py
Change-Id: I0ed0044129b1671b2c5dd1b9fa2e70a9b4475dc5
diff --git a/client/usb_libusb.cpp b/client/usb_libusb.cpp
index e7f44c6..7025f28 100644
--- a/client/usb_libusb.cpp
+++ b/client/usb_libusb.cpp
@@ -412,8 +412,13 @@
if (it != usb_handles.end()) {
if (!it->second->device_handle) {
// If the handle is null, we were never able to open the device.
- unregister_usb_transport(it->second.get());
+
+ // Temporarily release the usb handles mutex to avoid deadlock.
+ std::unique_ptr<usb_handle> handle = std::move(it->second);
usb_handles.erase(it);
+ lock.unlock();
+ unregister_usb_transport(handle.get());
+ lock.lock();
} else {
// Closure of the transport will erase the usb_handle.
}