Set 'java.rmi.server.hostname' property on client too
The RMI documentation (http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/javarmiproperties.html) says it is useful to set up a `java.rmi.server.hostname` system property on a client and a server. When the property is set up on a client, I saw that "RenewClean" threads stopped listening to my external IP, so all client and server threads are now only listening the loopback interface. I also changed the way the property is set up on the server side: before the change it was passed in jvmargs at a process launcher. I moved this code directly to the main method of the daemon, because it is easy to forget to set up the property, when running the main for debug purposes.
This commit is contained in:
+2
-3
@@ -94,6 +94,7 @@ object KotlinCompilerClient {
|
||||
leaseSession: Boolean,
|
||||
sessionAliveFlagFile: File? = null
|
||||
): ServiceWithSession? = connectLoop(reportingTargets) {
|
||||
setupServerHostName()
|
||||
val (service, newJVMOptions) = tryFindSuitableDaemonOrNewOpts(File(daemonOptions.runFilesPath), compilerId, daemonJVMOptions, { cat, msg -> reportingTargets.report(cat, msg) })
|
||||
if (service != null) {
|
||||
// the newJVMOptions could be checked here for additional parameters, if needed
|
||||
@@ -370,9 +371,7 @@ object KotlinCompilerClient {
|
||||
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
||||
val platformSpecificOptions = listOf(
|
||||
// hide daemon window
|
||||
"-Djava.awt.headless=true",
|
||||
// prevent host name resolution
|
||||
"-Djava.rmi.server.hostname=${LoopbackNetworkInterface.loopbackInetAddressName}")
|
||||
"-Djava.awt.headless=true")
|
||||
val args = listOf(
|
||||
javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)) +
|
||||
platformSpecificOptions +
|
||||
|
||||
@@ -96,3 +96,10 @@ fun findPortAndCreateRegistry(attempts: Int, portRangeStart: Int, portRangeEnd:
|
||||
throw IllegalStateException("Cannot find free port in $attempts attempts", lastException)
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to be set up on both client and server to prevent localhost resolution,
|
||||
* which may be slow and can cause a timeout when there is a network problem/misconfiguration.
|
||||
*/
|
||||
fun setupServerHostName() {
|
||||
System.setProperty("java.rmi.server.hostname", LoopbackNetworkInterface.loopbackInetAddressName)
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ object KotlinCompileDaemon {
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
setupServerHostName()
|
||||
|
||||
log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "<unknown>"))
|
||||
log.info("daemon JVM args: " + ManagementFactory.getRuntimeMXBean().inputArguments.joinToString(" "))
|
||||
|
||||
Reference in New Issue
Block a user