KeepSafe/ReLinker

Loaded Libraries Cache is not thread-safe

georgi-neykov-hub opened this issue · 2 comments

The HashSet-based loadedLibraries field inReLinkerInstance holding the names of already loaded library names is not thread-safe or guarded with a mutex. Relinker.loadLibrary() can be called from multiple threads either by user code or by loading asynchronously via a LoadListener, so it is a good idea to either use a lock on the Set, or Collections.synchonizedSet() or better, just pick something appropiate from java.util.concurrent like a ConcurrentHashMap wrapped with Collections.newSetFromMap()

Thanks for bringing this up.
Do you ever run into the issue where you load it from multiple threads? For us, we load libraries on app start from one place.

It would be great if you'd open a PR for this. I think there is no downside in making it thread safe.

I will do a fork and open a PR.
There one more thing in my mind for which I am not sure to open an issue or just merge it with the current change request. Currently I am using the library though a singleton-like wrapper which does not need an Context argument, but uses a non-exported ContentProvider which gets a reference to the application context on launch of the app. This way I very much have a drop-in replacement for System.loadLibray().
Do you interest in such a change, I can open a PR for it as well?