Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58fd5db6 authored by Jayant Chowdhary's avatar Jayant Chowdhary
Browse files

camera ndk: Fix deadlock when ~ACameraCaptureSession and stopLooperAndDisconnect() race



The following thread race was possible:

Thread 1: ACameraDevice_close() calls CameraDevice::stopLooperAndDisconnect() and grabs
          the device lock. It hasn't reached the point where the device actually starts
          disconnecting so CameraDevice::mClosing is still false.

Thread 2: Starts processing a callback on the camera2 libraries Looper thread and gets to
          ~ACameraCaptureSession(). Here it checks, CameraDevice::mClosing and sees that its
          false, so it goes ahead and tries to grab hold of the device lock, but that's
          locked by Thread 1

Thread 1: Continues execution and finishes CameraDevice::disconnect(), its only now that
          CameraDevice::mClosing has been set to true. Now Thread 1 waits for the Looper
          thread (Thread2) to finish, which will of course never happen since Thread2 is waiting on
          the device lock with thread 1 already has.

So we drop the device lock while stopping the looper thread in
CameraDevice::stopLooperAndDisconnect(). Methods in Looper thread which
need the device lock do lock it themselves.

Bug: 435733282

Test: atest NativeCameraDeviceTest.java; camera2 vndk

Flag: EXEMPT bugfix

Change-Id: I7ac4b962e3cef1df0c9d7b5bc05d3e22c5ca82ff
Signed-off-by: default avatarJayant Chowdhary <jchowdhary@google.com>
parent faf5112d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment