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

chore: Improve error handling when native lib fails to load #1000

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions common/src/main/java/org/apache/comet/NativeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ public abstract class NativeBase {

private static final String libraryToLoad = System.mapLibraryName(NATIVE_LIB_NAME);
private static boolean loaded = false;
private static volatile Throwable loadErr = null;
private static final String searchPattern = "libcomet-";

static {
if (!isLoaded()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load is a no-op if loaded == false so no need for this conditional here

try {
load();
} catch (Throwable th) {
LOG.warn("Failed to load comet library", th);
// logging may not be initialized yet, so also write to stderr
System.err.println("Failed to load comet library: " + th.getMessage());
loadErr = th;
}
}

public static synchronized boolean isLoaded() {
public static synchronized boolean isLoaded() throws Throwable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called from isCometEnabled and we already had error handling here which could never be triggered due to isLoaded never being capable of throwing an exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: calling isLoaded could have resulted in the NoClassDefFoundError but this did not have details of root cause.

if (loadErr != null) {
throw loadErr;
}
return loaded;
}

Expand Down
Loading