[#3680] Enabled SecurityManager results in ClassNotFoundError during io.netty.util.NetUtil initialization
Motivation: When a SecurityManager is in place that preven reading the somaxconn file trying to bootstrap a channel later will result in a ClassNotFoundError. Modifications: - Reading the file in a privileged block. Result: No more ClassNotFoundError when a SecurityManager is in place.
This commit is contained in:
parent
4baea3ea7a
commit
18ace807b8
@ -29,6 +29,8 @@ import java.net.InetAddress;
|
|||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -231,38 +233,45 @@ public final class NetUtil {
|
|||||||
LOOPBACK_IF = loopbackIface;
|
LOOPBACK_IF = loopbackIface;
|
||||||
LOCALHOST = loopbackAddr;
|
LOCALHOST = loopbackAddr;
|
||||||
|
|
||||||
// Determine the default somaxconn (server socket backlog) value of the platform.
|
// As a SecurityManager may prevent reading the somaxconn file we wrap this in a privileged block.
|
||||||
// The known defaults:
|
//
|
||||||
// - Windows NT Server 4.0+: 200
|
// See https://github.com/netty/netty/issues/3680
|
||||||
// - Linux and Mac OS X: 128
|
SOMAXCONN = AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||||
int somaxconn = PlatformDependent.isWindows() ? 200 : 128;
|
@Override
|
||||||
File file = new File("/proc/sys/net/core/somaxconn");
|
public Integer run() {
|
||||||
if (file.exists()) {
|
// Determine the default somaxconn (server socket backlog) value of the platform.
|
||||||
BufferedReader in = null;
|
// The known defaults:
|
||||||
try {
|
// - Windows NT Server 4.0+: 200
|
||||||
in = new BufferedReader(new FileReader(file));
|
// - Linux and Mac OS X: 128
|
||||||
somaxconn = Integer.parseInt(in.readLine());
|
int somaxconn = PlatformDependent.isWindows() ? 200 : 128;
|
||||||
if (logger.isDebugEnabled()) {
|
File file = new File("/proc/sys/net/core/somaxconn");
|
||||||
logger.debug("{}: {}", file, somaxconn);
|
if (file.exists()) {
|
||||||
}
|
BufferedReader in = null;
|
||||||
} catch (Exception e) {
|
|
||||||
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
|
||||||
} finally {
|
|
||||||
if (in != null) {
|
|
||||||
try {
|
try {
|
||||||
in.close();
|
in = new BufferedReader(new FileReader(file));
|
||||||
|
somaxconn = Integer.parseInt(in.readLine());
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}: {}", file, somaxconn);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Ignored.
|
logger.debug("Failed to get SOMAXCONN from: {}", file, e);
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return somaxconn;
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SOMAXCONN = somaxconn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user