Skip to content

Commit

Permalink
Let users opt-in for app initialization failures without native libs (#…
Browse files Browse the repository at this point in the history
…2006)

Motivation:

#1979 fails app initialization if native transport libs can not be
loaded. This is too aggressive. Instead, keep warning users and let
them opt-in for the enforced behavior.

Modifications:

- Fail initialization only if users explicitly opt-it for this using
`-Dio.servicetalk.transport.netty.requireNativeLibs=true`;
- Improve exception and log messages;

Result:

Users can enforce requirement for native libs if they need.
  • Loading branch information
idelpivnitskiy authored Dec 10, 2021
1 parent bbae7d0 commit 6a74663
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
final class NativeTransportUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(NativeTransportUtils.class);
private static final String REQUIRE_NATIVE_LIBS_NAME = "io.servicetalk.transport.netty.requireNativeLibs";
private static final boolean REQUIRE_NATIVE_LIBS = getBoolean(REQUIRE_NATIVE_LIBS_NAME);
private static final String NETTY_NO_NATIVE_NAME = "io.netty.transport.noNative";
private static final boolean NETTY_NO_NATIVE = getBoolean(NETTY_NO_NATIVE_NAME);

Expand All @@ -63,16 +65,30 @@ private NativeTransportUtils() {
}

private static void reactOnUnavailability(final String transport, final String os, final Throwable cause) {
if (REQUIRE_NATIVE_LIBS) {
throw new IllegalStateException("Can not load required \"io.netty:netty-transport-native-" + transport +
":$nettyVersion:" + os + '-' + normalizedArch() + "\", it may impact responsiveness, " +
"reliability, and performance of the application. Fix the deployment to make sure the native " +
"libraries are packaged and can be loaded. Otherwise, unset \"-D" + REQUIRE_NATIVE_LIBS_NAME +
"=true\" system property to let the application start without native libraries and set \"-D" +
NETTY_NO_NATIVE_NAME + "=true\" if running without native libs is intentional. " +
"For more information, see https://netty.io/wiki/native-transports.html", cause);
}
if (NETTY_NO_NATIVE) {
LOGGER.info("io.netty:netty-transport-native-{} is explicitly disabled with \"-D{}=true\". Note that it " +
"may impact responsiveness, reliability, and performance of the application. For more information" +
", see https://netty.io/wiki/native-transports.html", transport, NETTY_NO_NATIVE_NAME);
return;
"may impact responsiveness, reliability, and performance of the application. ServiceTalk " +
"recommends always running with native libraries. Consider using \"-D{}=true\" to fail " +
"application initialization without native libs. For more information, see " +
"https://netty.io/wiki/native-transports.html",
transport, NETTY_NO_NATIVE_NAME, REQUIRE_NATIVE_LIBS_NAME);
} else {
LOGGER.warn("Can not load \"io.netty:netty-transport-native-{}:$nettyVersion:{}-{}\", it may impact " +
"responsiveness, reliability, and performance of the application. ServiceTalk recommends always " +
"running with native libraries. Consider using \"-D{}=true\" to fail application initialization " +
"without native libraries. If this is intentional, let netty know about it using \"-D{}=true\". " +
"For more information, see https://netty.io/wiki/native-transports.html",
transport, os, normalizedArch(), REQUIRE_NATIVE_LIBS_NAME, NETTY_NO_NATIVE_NAME);
}
throw new IllegalStateException("Can not load \"io.netty:netty-transport-native-" + transport +
":$nettyVersion:" + os + '-' + normalizedArch() + "\", it may impact responsiveness, reliability, " +
"and performance of the application. Explicitly set \"-D" + NETTY_NO_NATIVE_NAME + "=true\" if this " +
"is intentional. For more information, see https://netty.io/wiki/native-transports.html", cause);
}

/**
Expand Down

0 comments on commit 6a74663

Please sign in to comment.