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 16:08:26 UTC 2024
On Fri, 7 Jun 2024 15:48:27 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> 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
>
> Thank you for explaining that. I now understand what you meant. So, the fact that the `Agent` no longer launches the `AgentServer` with a `-host` program argument makes the `-host` an unnecessary option to keep around. The use of loopback address was done in a separate PR recently, which is where this option was made unnecessary. I would prefer to discuss the possibility of either retaining or dropping that option, with Jon and others and address it separately if that's OK with you.
As you wish, there's no point in retaining it with the current agent loopback address listening policy.
Additionally, it might also be worth wrapping the Socket call in a try catch, to handle a connect timeout more gracefully by logging to the AgentServer's log file. The Exception can still be rethrown. Currently the exception will appear in the agent.trace file for example,
[2023-06-22 11:45:55,165] Agent[39]: stderr: java.net.ConnectException: Operation timed out
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/sun.nio.ch.Net.connect0(Native Method)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/sun.nio.ch.Net.connect(Net.java:589)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/sun.nio.ch.Net.connect(Net.java:578)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:583)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/java.net.Socket.connect(Socket.java:751)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/java.net.Socket.connect(Socket.java:686)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/java.net.Socket.<init>(Socket.java:555)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at java.base/java.net.Socket.<init>(Socket.java:356)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at com.sun.javatest.regtest.agent.AgentServer.<init>(AgentServer.java:209)
[2023-06-22 11:45:55,165] Agent[39]: stderr: at com.sun.javatest.regtest.agent.AgentServer.main(AgentServer.java:71)
BUT if this also appear in an AgentServer trace file it will assist with failure diagnosis.
-------------
PR Review Comment: https://git.openjdk.org/jtreg/pull/195#discussion_r1631423029
More information about the jtreg-dev
mailing list