RFR: 7903730: Enhance the agentvm to be tolerant to unexpected connection on the port the Agent listens on for handshake with the AgentServer [v3]

Mark Sheppard msheppar at openjdk.org
Fri Jun 7 15:44:29 UTC 2024


On Fri, 7 Jun 2024 11:40:13 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> src/share/classes/com/sun/javatest/regtest/agent/AgentServer.java line 219:
>> 
>>> 217:         if (port > 0) {
>>> 218:             log("Connecting to " + host + ":" + port);
>>> 219:             Socket s = new Socket(host, port);
>> 
>> This only works if the host argument is not specified on the AgentServer command line, as the Agent now listens on the loopback address  and no longer the wildcard address.
>> Typically the host argument, in the launching command line of the AgentServer, is not specified. But now an Agent  is listening on loopback address making the -host argument redundant. So maybe -host should be removed from common line processing
>
> Hello Mark, I read this a couple of times but didn't fully understand this suggestion. Right now the `host` variable gets default set to loopback address:
> 
> 
> // by default use loopback address. if "-host" is specified, this will
> // then be overridden by that value
> InetAddress host = InetAddress.getLoopbackAddress();
> 
> 
> but as the code comment states, if the `AgentServer` program was launched with a `-host <val>` then the `host` variable here is updated/set to the new value that is provided to value. So when the code does indeed reach the point of calling this `Socket` constructor, the `host` variable would have the correct host.
> Did I misunderstand your suggestion?

your recent change to the Agent to use the loopback address only

 ServerSocket ss = new ServerSocket();
            // Ensure SO_REUSEADDR is false. (It is only needed if we're
            // using a fixed port.) The default setting for SO_REUSEADDR
            // is platform-specific, and Solaris has it on by default.
            ss.setReuseAddress(false);
            InetAddress loopbackAddr = InetAddress.getLoopbackAddress();
            final int backlog = MAX_ACCEPT_ATTEMPTS;
            ss.bind(new InetSocketAddress(loopbackAddr, /*port:*/ 0), backlog);
            final int port = ss.getLocalPort();

so the -host argument is now redundant, if it were passed as an argument then an AgentServer couldn't connect to its peer Agent

-------------

PR Review Comment: https://git.openjdk.org/jtreg/pull/195#discussion_r1631398295


More information about the jtreg-dev mailing list