[#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,14 +245,22 @@ 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);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -264,11 +272,6 @@ public final class NetUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return somaxconn;
|
return somaxconn;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user