RFR: 8334297: (so) java/nio/channels/SocketChannel/OpenLeak.java should not depend on SecurityManager [v2]

Daniel Fuchs dfuchs at openjdk.org
Fri Jun 14 15:45:21 UTC 2024


On Fri, 14 Jun 2024 15:33:08 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> The test java/nio/channels/SocketChannel/OpenLeak.java depends on the SecurityManager to trigger an exception in SocketChannel::connect.
>> 
>> This change rewrites it to connect to a TCP reserved port instead, such as port 47, 51, or 61, in order to trigger a `ConnectException` instead of a `SecurityException`.
>> 
>> The original issue that this test tried to check for was:
>> https://bugs.openjdk.org/browse/JDK-6548464
>
> Daniel Fuchs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improve test for better coverage

There are two places of interest for this test where `SocketChannel` is closed: one is in `SocketChannel::connect`, if an `IOException` is thrown by e.g. `Net::connect`.
The other is in `SocketChannel::open(SocketAddress)`, if any `Throwable` is thrown by `SocketChannel::connect`.

The `SecurityException` was thrown by `checkRemote(SocketAddress)` called before entering the try/catch in `SocketChannel::connect`, and exercised that second path.

By analysing the code I noticed that `checkRemote` would also throw if an unresolved `InetSocketAddress` was passed to `SocketChannel::open(SocketAddress)` - which is closer to what the original test was testing, and would also exercise the latter path of execution.

I manually removed the `close()` call in `SocketChannel::open` and managed to make the test fail with `SoccketException("too many open files")`, but for that I had to increase the number of loops from 100000 to 250000 on my local machine. So I did that too.

I'm currently verifying the test is still stable in the CI, but I believe testing both paths - one with an unreachable port/address and one with an unresolved address is what we should do.

I have updated the test in consequence.

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

PR Comment: https://git.openjdk.org/jdk/pull/19723#issuecomment-2168296048


More information about the nio-dev mailing list