[#4936] NetUtil can prevent using Netty due to SecurityManager denial
Motivation: A custom SecurityManager may prevent calling File.exists() and so throw a SecurityException in the static init block of NetUtil. Modifications: Correctly catch the exception and so allow to static init NetUtil. Result: Allow static init method of NetUtil to work even with custom SecurityManager.
This commit is contained in:
parent
35771dd1cd
commit
97df3cb039
@ -245,28 +245,31 @@ public final class NetUtil {
|
|||||||
// - Linux and Mac OS X: 128
|
// - Linux and Mac OS X: 128
|
||||||
int somaxconn = PlatformDependent.isWindows() ? 200 : 128;
|
int somaxconn = PlatformDependent.isWindows() ? 200 : 128;
|
||||||
File file = new File("/proc/sys/net/core/somaxconn");
|
File file = new File("/proc/sys/net/core/somaxconn");
|
||||||
if (file.exists()) {
|
BufferedReader in = null;
|
||||||
BufferedReader in = null;
|
try {
|
||||||
try {
|
// file.exists() may throw a SecurityException if a SecurityManager is used, so execute it in the
|
||||||
|
// try / catch block.
|
||||||
|
// See https://github.com/netty/netty/issues/4936
|
||||||
|
if (file.exists()) {
|
||||||
in = new BufferedReader(new FileReader(file));
|
in = new BufferedReader(new FileReader(file));
|
||||||
somaxconn = Integer.parseInt(in.readLine());
|
somaxconn = Integer.parseInt(in.readLine());
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("{}: {}", file, somaxconn);
|
logger.debug("{}: {}", file, somaxconn);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
if (logger.isDebugEnabled()) {
|
||||||
} finally {
|
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
||||||
if (in != null) {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignored.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
if (logger.isDebugEnabled()) {
|
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
||||||
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return somaxconn;
|
return somaxconn;
|
||||||
|
Loading…
Reference in New Issue
Block a user