Skip to content

Commit

Permalink
On so load failure, attempt a single retry after checking if the nati…
Browse files Browse the repository at this point in the history
…ve lib directory has changed

Summary:
When failing to load an so, it's possibly due to a native lib dir change, which is not being caught in the execution of `doLoadLibraryBySoName`, likely due to a race condition.

Attempt a single retry after checking if the directory has changed

Reviewed By: boguscoder

Differential Revision: D20380938

fbshipit-source-id: ef6039ad077ee7cfa13b62c7d8c2b1018b59c56c
  • Loading branch information
Matthew Langille authored and facebook-github-bot committed Mar 11, 2020
1 parent 890dca1 commit f226061
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,40 @@ public static File unpackLibraryAndDependencies(String shortName) throws Unsatis

private static void doLoadLibraryBySoName(
String soName, int loadFlags, StrictMode.ThreadPolicy oldPolicy) throws IOException {
// Load the library, and if fails - attempt a single retry to update ApplicationSoSource
try {
doLoadLibraryBySoNameImpl(soName, loadFlags, oldPolicy);
} catch (UnsatisfiedLinkError e) {
if (sApplicationSoSource != null) {
Log.e(TAG, "Failed to load library, attempting reload of ApplicationSoSource.");

boolean updated = false;
sSoSourcesLock.writeLock().lock();
try {
if (sApplicationSoSource.checkAndMaybeUpdate()) {
sSoSourcesVersion++;
updated = true;
}
} finally {
sSoSourcesLock.writeLock().unlock();
}
// If updated - attempt second reload
if (updated) {
Log.e(TAG, "ApplicationSoSource updated, attempting load again.");
doLoadLibraryBySoNameImpl(soName, loadFlags, oldPolicy);
} else {
// Propagate original error
throw e;
}
} else {
// Propagate original error
throw e;
}
}
}

private static void doLoadLibraryBySoNameImpl(
String soName, int loadFlags, StrictMode.ThreadPolicy oldPolicy) throws IOException {

int result = SoSource.LOAD_RESULT_NOT_FOUND;
sSoSourcesLock.readLock().lock();
Expand Down

0 comments on commit f226061

Please sign in to comment.