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

Commit 4432d5a1 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Gerrit Code Review
Browse files

AssetAtlasService: fix a potential race condition

Backported from marshmallow-release.

Currently worker threads in computeBestConfiguration may NOT completely
finish before timeout.  But the code will start using the result while
the worker threads are still working on the same object.  This may
cause exceptions.

b/19966623

Change-Id: I62ffcb796d648891ee339b6a978f575ebad8352b
parent 3ba4c35f
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -416,12 +416,20 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
                new Thread(worker, "Atlas Worker #" + (i + 1)).start();
            }

            boolean isAllWorkerFinished;
            try {
                signal.await(10, TimeUnit.SECONDS);
                isAllWorkerFinished = signal.await(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Log.w(LOG_TAG, "Could not complete configuration computation");
                return null;
            }

            if (!isAllWorkerFinished) {
                // We have to abort here, otherwise the async updates on "results" would crash the
                // sort later.
                Log.w(LOG_TAG, "Could not complete configuration computation before timeout.");
                return null;
            }
        }

        if (results.size() == 0) {