RFR: 8343791: Socket.connect API should document whether the socket will be closed when hostname resolution fails or another error occurs [v4]
Volkan Yazıcı
duke at openjdk.org
Wed Nov 20 13:35:31 UTC 2024
On Wed, 20 Nov 2024 12:42:46 GMT, Volkan Yazıcı <duke at openjdk.org> wrote:
>> If you take on board the other feedback then you can reduce the scope of the try-catch to just the bind, e.g.
>>
>> if (localAddr != null) {
>> try {
>> bind(localAddr);
>> } catch (Throwable ex) {
>> try {
>> close();
>> } catch (Throwable ce) { ex.addSuppressed(ce); }
>> throw ex;
>> }
>> }
>> connect(address); // closes Socket if it throws
>
> Fixed in 424fc8ccd3a495a49f859f0cfc563cf463b3efeb.
Imagine `bind()` succeeding, yet `connect()` failing due to an `IAE` thrown by `SocketImpl#connect()`. This would leave the socket in `BOUND` state. Hence, shouldn't we include the `connect()` in the try-catch block too?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22160#discussion_r1850325806
More information about the net-dev
mailing list