From ad869cc908ff22956f8df47cb127e3446793b787 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 12 Jul 2016 13:56:35 -0700 Subject: [PATCH] Thread-safe pipe teardown during restore operations Bug 29135140 Change-Id: Id474f180815318618ec28ff953dc0cab892f781e --- .../server/backup/BackupManagerService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 8e0ec520c5ba3..8bb59db9981f3 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -5700,16 +5700,21 @@ public class BackupManagerService { } void tearDownPipes() { - if (mPipes != null) { - try { - mPipes[0].close(); - mPipes[0] = null; - mPipes[1].close(); - mPipes[1] = null; - } catch (IOException e) { - Slog.w(TAG, "Couldn't close agent pipes", e); + // Teardown might arise from the inline restore processing or from the asynchronous + // timeout mechanism, and these might race. Make sure we don't try to close and + // null out the pipes twice. + synchronized (this) { + if (mPipes != null) { + try { + mPipes[0].close(); + mPipes[0] = null; + mPipes[1].close(); + mPipes[1] = null; + } catch (IOException e) { + Slog.w(TAG, "Couldn't close agent pipes", e); + } + mPipes = null; } - mPipes = null; } }