Fixes a thread safety issue (a time-of-check-time-of-use bug) in BatteryExternalStatsWorker that causes system_server crashes in VROS device.

Synchronize BatteryExternalStatsWorker.shutdown(). Without this, a shutdown can sneak in-between the checks to mExecutor.isShutdown() and other
mExecutor calls, causing the later calls to fail with a RejectedExecutionException instead of having the intended behavior for
a shutdown mExecutor.

Test: There is no known test case for regression testing. This is a race condition, so any test case would inherently be flaky.
The correctness of the patch is easily seen by observing the time-of-check-time-of-use issues that arise throughout BatteryExternalStatsWorker.java
before the patch is applied.

Change-Id: Id690f3451f86ac536b186021ef4fb63827bc863e
This commit is contained in:
beiyifb
2023-05-03 16:25:12 -07:00
parent f6f72da24f
commit 68a22d8d8a

View File

@@ -399,7 +399,7 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
}
}
public void shutdown() {
public synchronized void shutdown() {
mExecutorService.shutdownNow();
}