[#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
f812180c2d
commit
f67b14bf35
@ -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,6 +233,12 @@ public final class NetUtil {
|
|||||||
LOOPBACK_IF = loopbackIface;
|
LOOPBACK_IF = loopbackIface;
|
||||||
LOCALHOST = loopbackAddr;
|
LOCALHOST = loopbackAddr;
|
||||||
|
|
||||||
|
// As a SecurityManager may prevent reading the somaxconn file we wrap this in a privileged block.
|
||||||
|
//
|
||||||
|
// See https://github.com/netty/netty/issues/3680
|
||||||
|
SOMAXCONN = AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer run() {
|
||||||
// Determine the default somaxconn (server socket backlog) value of the platform.
|
// Determine the default somaxconn (server socket backlog) value of the platform.
|
||||||
// The known defaults:
|
// The known defaults:
|
||||||
// - Windows NT Server 4.0+: 200
|
// - Windows NT Server 4.0+: 200
|
||||||
@ -261,8 +269,9 @@ public final class NetUtil {
|
|||||||
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
logger.debug("{}: {} (non-existent)", file, somaxconn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return somaxconn;
|
||||||
SOMAXCONN = somaxconn;
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user