Fix race conditions in removing dying process record

While waiting for the death of a process, if its subsequent process
record is created and killed immediately, we may end up removing
the former process record from the dying process list.

Bug: 201305599
Bug: 206336727
Test: Presubmit
Change-Id: I00521a5561d98f2df6f52443b9e23025faeaeb3c
This commit is contained in:
Jing Ji
2021-11-16 00:04:48 -08:00
parent eb7f4c076f
commit 0120825e34
2 changed files with 11 additions and 1 deletions

View File

@@ -11910,6 +11910,15 @@ public class ActivityManagerService extends IActivityManager.Stub
// If this is a preceding instance of another process instance
allowRestart = mProcessList.handlePrecedingAppDiedLocked(app);
// If somehow this process was still waiting for the death of its predecessor,
// (probably it's "killed" before starting for real), reset the bookkeeping.
final ProcessRecord predecessor = app.mPredecessor;
if (predecessor != null) {
predecessor.mSuccessor = null;
predecessor.mSuccessorStartRunnable = null;
app.mPredecessor = null;
}
// If the caller is restarting this app, then leave it in its
// current lists and let the caller take care of it.
if (restarting) {

View File

@@ -5143,7 +5143,8 @@ public final class ProcessList {
}
Watchdog.getInstance().processDied(app.processName, app.getPid());
if (app.getDeathRecipient() == null) {
if (app.getDeathRecipient() == null
&& mDyingProcesses.get(app.processName, app.uid) == app) {
// If we've done unlinkDeathRecipient before calling into this, remove from dying list.
mDyingProcesses.remove(app.processName, app.uid);
app.setDyingPid(0);