Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loaded Libraries Cache is not thread-safe #54

Open
georgi-neykov-hub opened this issue Jan 2, 2019 · 2 comments
Open

Loaded Libraries Cache is not thread-safe #54

georgi-neykov-hub opened this issue Jan 2, 2019 · 2 comments

Comments

@georgi-neykov-hub
Copy link

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()

@philippb
Copy link
Contributor

philippb commented Feb 7, 2019

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.

@georgi-neykov-hub
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants