From 6a74663a56a016e2b7f10cea05e10dbebcbe5900 Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Thu, 9 Dec 2021 19:07:57 -0600 Subject: [PATCH] Let users opt-in for app initialization failures without native libs (#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. --- .../netty/internal/NativeTransportUtils.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/servicetalk-transport-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NativeTransportUtils.java b/servicetalk-transport-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NativeTransportUtils.java index d25e0cfe88..ad990feadd 100644 --- a/servicetalk-transport-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NativeTransportUtils.java +++ b/servicetalk-transport-netty-internal/src/main/java/io/servicetalk/transport/netty/internal/NativeTransportUtils.java @@ -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); @@ -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); } /**