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

LinkageError when two programs use ObjectBox and share the same .dll. #1096

Open
Ckblck opened this issue Aug 25, 2022 · 2 comments
Open

LinkageError when two programs use ObjectBox and share the same .dll. #1096

Ckblck opened this issue Aug 25, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Ckblck
Copy link

Ckblck commented Aug 25, 2022

Describe the bug
A Java program will not work if another Java program uses ObjectBox.

Basic info:

  • ObjectBox version: 3.2.1
  • Reproducibility: always
  • Device: Desktop Java
  • OS: Windows 10, Windows 11 & Linux

To Reproduce
See the Is there anything special about your app?.

Probable way to reproduce the behaviour without using Spigot plugins:

  1. Create two projects that use ObjectBox and place them in the same folder.
  2. Execute each application
  3. See error

Way to reproduce the behaviour USING Spigot plugins:

  1. Create two Spigot plugins that use ObjectBox.
  2. Place the plugins under the \plugins folder.
  3. Start the server & see the error for one plugin.

Expected behavior
ObjectBox should be able to use different .dll files in order for this error not to happen. This could be worked around by providing a method to specify the location of the .dll file, #973

Logs, stack traces

[15:34:38 WARN]: Caused by: java.lang.LinkageError: [ObjectBox] Loading native library failed, please report this to us: vendor=Oracle Corporation,os=linux,os.arch=amd64,model=64,linux=true,machine=x86_64
[21:23:30 WARN]: java.io.FileNotFoundException: objectbox-jni-windows-x64.dll (El proceso no tiene acceso al archivo porque está siendo utilizado por otro proceso)
[21:23:30 WARN]:        at java.base/java.io.FileOutputStream.open0(Native Method)
[21:23:30 WARN]:        at java.base/java.io.FileOutputStream.open(FileOutputStream.java:293)
[21:23:30 WARN]:        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
[21:23:30 WARN]:        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:184)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//io.objectbox.internal.NativeLibraryLoader.checkUnpackLib(NativeLibraryLoader.java:227)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//io.objectbox.internal.NativeLibraryLoader.<clinit>(NativeLibraryLoader.java:75)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//io.objectbox.BoxStore.<init>(BoxStore.java:262)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//io.objectbox.BoxStoreBuilder.build(BoxStoreBuilder.java:516)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//dev.ckblck.referrals.logic.reward.storage.pending.PendingRewardDatabase.loadDatabase(PendingRewardDatabase.java:79)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//dev.ckblck.referrals.logic.reward.storage.pending.PendingRewardDatabase.<init>(PendingRewardDatabase.java:30)
[21:23:30 WARN]:        at Plugin-1.0-SNAPSHOT.jar//dev.ckblck.referrals.Plugin.lambda$onEnable$0(Plugin.java:82)
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
[21:23:30 WARN]: java.util.concurrent.CompletionException: java.lang.LinkageError: [ObjectBox] Loading native library failed, please report this to us: vendor=Amazon.com Inc.,os=windows 10,os.arch=amd64,model=64,linux=false,machine=null
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
[21:23:30 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
[21:23:30 WARN]:        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
[21:23:30 WARN]: Caused by: java.lang.LinkageError: [ObjectBox] Loading native library failed, please report this to us: vendor=Amazon.com Inc.,os=windows 10,os.arch=amd64,model=64,linux=false,machine=null

Additional context

  • Is there anything special about your app?
    I'm using ObjectBox for Spigot Java plugins. In this context, the objectbox-jni-windows-x64 is being shared for all the plugins that use ObjectBox, and as far as I'm aware, there is no viable way to modify the location of the objectbox-jni-windows-x64 file for each instance. Possibly related with Changing destination directory of native libraries #973
    The Spigot standalone loads each plugin and when two plugins are using ObjectBox, the error occurrs.
@Ckblck Ckblck added the bug Something isn't working label Aug 25, 2022
@greenrobot-team greenrobot-team removed the bug Something isn't working label Aug 29, 2022
@greenrobot-team
Copy link
Member

Thanks for reporting! First of all, this is the error message:
java.io.FileNotFoundException: objectbox-jni-windows-x64.dll (El proceso no tiene acceso al archivo porque está siendo utilizado por otro proceso)
Translation: The process does not have access to the file because it is in use by another process

It appears this is happening while trying to extract the native library and trying to write to an existing library file.

if (!file.exists() || file.length() != length || file.lastModified() != lastModified) {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
try {
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));

There is a check if the file already exists to prevent extracting again. However, there might be a race if two processes extract in parallel.

We might be able to solve this by introducing file locking (assuming that loading the library can happen from multiple processes in parallel).

We'll update this issue when we know a fix is available.

As for workarounds: can you change the working directory of the plugins so they extract the native library to a different folder? Or prevent them running in parallel?

@greenrobot-team greenrobot-team added the enhancement New feature or request label Aug 29, 2022
@Ckblck
Copy link
Author

Ckblck commented Sep 1, 2022

can you change the working directory of the plugins so they extract the native library to a different folder? Or prevent them running in parallel?

Unfortunately, I'm afraid I'm unable to work around this issue, I've checked if I could take advantage of reflection, but without success.

Nevertheless, I'm thankful the issue has been registered, I'll patiently wait for the fix.

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

No branches or pull requests

2 participants