[Java] More carefully ensure sockets are closed in `NioPeerHandler`
authorMatt Corallo <git@bluematt.me>
Thu, 27 Jan 2022 18:39:52 +0000 (18:39 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 2 Feb 2022 19:30:30 +0000 (19:30 +0000)
commitebef1f83fe4f70ba2f5c683a69f08e7ba32c8ad3
tree2ac54a680d6c84ccd7ef0e2771315ae2c88f6ade
parent7a5639be20902abaa73d5dab53664f89bec70357
[Java] More carefully ensure sockets are closed in `NioPeerHandler`

There is no indication that the sockets are leaking in the handling
loop, but its good to be careful and ensure we always both close
the SocketChannel and cancel the key registration.

During connection, however, it appears we may leak a SocketChannel
if the connection times out, leaking a file descriptor at least
until the GC kicks in and cleans up after us.  Here we are more
careful.
src/main/java/org/ldk/batteries/NioPeerHandler.java