Elytrium / Elytrium/LimboAuth

[BUG] SQL drivers are not relocated when using DatabaseLibrary#connectToORM

Open
#113 6 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
238
Forks
125
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
LimboAuth relocates *most* of the libraries it uses (see [build.gradle](https://github.com/Elytrium/LimboAuth/blob/9b173fcef380c68d2f4ae1865fd40e3b4fff3081/build.gradle#L107-L120)). However, JDBC drivers in the [DatabaseLibrary](https://github.com/Elytrium/LimboAuth/blob/9b173fcef380c68d2f4ae1865fd40e3b4fff3081/src/main/java/net/elytrium/limboauth/dependencies/DatabaseLibrary.java#L36) enum are **not** relocated when they are downloaded. The driver classes **should** be remapped to the proper namespace, but they are not, which causes conflicts with other plugins.

This matters because the `DatabaseLibrary#connectToORM` method, used by LimboAuth, loads the dependency by attaching it to the plugin classloader. As a result, the driver classes become visible to other plugins. (This is a problem for the same reason that forgetting to relocate dependencies in the `build.gradle` is a problem)

Note that the `DatabaseLibrary#connect` method is okay, because it loads the driver in an isolated classloader. Using an isolated classloader is an accepted practice for loading an unrelocated dependency. However, LimboAuth doesn't use the `connect` method anymore; it uses `connectToORM`.

**To Reproduce**
You can observe conflicts between LimboAuth and other plugins which use the MariaDB driver. For example, LibertyBans is a plugin which uses an isolated classloader for its own copy of the MariaDB driver. This leads to classloading violations in LibertyBans because some of the MariaDB classes are mixed up with the (same) classes loaded by LimboAuth. Because the same classes are loaded by two separate classloaders, classloading errors result.

Steps to reproduce the behavior:
1. Install LimboAuth and LibertyBans, for example
2. Configure both plugins to use MariaDB
3. Observe classloading violations in LibertyBans

See error: https://hastebin.bluetree242.dev/xeciqimeve.less

**Expected behavior**
LimboAuth relocates all of its dependencies which are not placed into an isolated classloader.

**Screenshots**
https://hastebin.bluetree242.dev/xeciqimeve.less

**Server Info (please complete the following information):**
- All Limbo plugins versions:
- LimboAuth 1.1.13
- LimboAPI 1.1.13
- LibertyBans 1.1.0-M3
- [/velocity dump](https://hastebin.bluetree242.dev/raduxoveno.json)

**Additional context**
You have a few options to solve the problem. You could relocate dependencies at runtime: other plugins use libraries to do this (however, if you use lucko's jar-relocator, make sure to depend on the latest version, because prior versions have bugs).

Another option would be to find a way to configure your ORM to use the isolated classloader. Then you could continue to use the `connect` method with an isolated classloader. For example, some libraries make use of the thread context classloader which instructs the ORM where to search for the driver. You'll have to consult your ORM documentation on this.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.