mkribs opened a new pull request, #2645: URL: https://github.com/apache/plc4x/pull/2645
`TcpTransportInstance`'s constructor only assigned the opened `SocketChannel` to its field after `bind()`, socket options, and `connect()` all succeeded. If `bind()` or a socket-option call threw (e.g. a pinned local port still held by a previous failed attempt), the already-open channel was never closed - leaking one fd per failed attempt. Note: `connect()` failures (timeout/refused) are **not** affected - `Socket.connect(SocketAddress, int)` already closes itself internally on failure (confirmed empirically). Only failures *before* `connect()` is reached (bind, socket options) leak. **Fix:** hold the channel in a local variable, only promote it to the `socketChannel` field once every setup step succeeds; explicitly close it in the constructor's catch block otherwise. **Testing:** added `testConstructor_failedBind_doesNotLeakFileDescriptors`, which deterministically forces a `BindException` (occupies a local port, configures the transport to bind to that same port) and asserts the open-file-descriptor count stays flat across repeated failures via `UnixOperatingSystemMXBean`. Verified the test fails without this fix (fd count grows ~1 per attempt) and passes with it, on Linux. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
