AudioFlinger: Workaround for dumpsys stall
Binder fds may not close immediately due to a race
condition when the last refcount is removed on the remote
binder thread and it is blocked in the kernel waiting for data.
Issue a binder ping command to unblock the remote binder thread
and complete the fd close / release.
Test: adb shell dumpsys media.audio_flinger (repeat many times)
Bug: 111997867
Bug: 177271958
Change-Id: I2237d1af430dfad08f22de6efaec9b04c19bdc5a
diff --git a/media/libaudiohal/impl/EffectsFactoryHalHidl.cpp b/media/libaudiohal/impl/EffectsFactoryHalHidl.cpp
index 9c4363c..f042b92 100644
--- a/media/libaudiohal/impl/EffectsFactoryHalHidl.cpp
+++ b/media/libaudiohal/impl/EffectsFactoryHalHidl.cpp
@@ -149,6 +149,18 @@
hidlHandle->data[0] = fd;
Return<void> ret = mEffectsFactory->debug(hidlHandle, {} /* options */);
native_handle_delete(hidlHandle);
+
+ // TODO(b/111997867, b/177271958) Workaround - remove when fixed.
+ // A Binder transmitted fd may not close immediately due to a race condition b/111997867
+ // when the remote binder thread removes the last refcount to the fd blocks in the
+ // kernel for binder activity. We send a Binder ping() command to unblock the thread
+ // and complete the fd close / release.
+ //
+ // See DeviceHalHidl::dump(), EffectHalHidl::dump(), StreamHalHidl::dump(),
+ // EffectsFactoryHalHidl::dumpEffects().
+
+ (void)mEffectsFactory->ping(); // synchronous Binder call
+
return processReturn(__FUNCTION__, ret);
}