Copilot commented on code in PR #2645:
URL: https://github.com/apache/plc4x/pull/2645#discussion_r3631366549


##########
plc4j/transports/tcp/src/main/java/org/apache/plc4x/java/transport/tcp/TcpTransportInstance.java:
##########
@@ -126,6 +131,13 @@ public TcpTransportInstance(InetSocketAddress 
remoteAddress, TcpTransportConfigu
             LOGGER.error(errorMsg, e);
             // errorMsg already embeds e.getMessage(); a single audit event 
avoids a duplicate.
             auditLog.write(AuditLogEventType.ERROR, "Error in constructor: " + 
errorMsg);

Review Comment:
   The constructor only cleans up the opened SocketChannel on IOException. If 
any unchecked exception is thrown during setup (e.g., InetSocketAddress 
construction for an invalid localPort, UnresolvedAddressException from connect, 
or a RuntimeException from logging/audit), the channel will still leak. Also, 
in the IOException path, auditLog.write() currently runs before 
channel.close(); if auditLog.write() throws, cleanup is skipped again. Consider 
guaranteeing cleanup before any other side effects and also closing on 
RuntimeException while preserving the original exception behavior.



-- 
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]

Reply via email to