Philippus commented on code in PR #3532:
URL: https://github.com/apache/pekko/pull/3532#discussion_r3955246764


##########
remote/src/main/scala/org/apache/pekko/remote/artery/aeron/ArteryAeronUdpTransport.scala:
##########
@@ -481,9 +481,9 @@ private[remote] class ArteryAeronUdpTransport(_system: 
ExtendedActorSystem, _pro
     import java.nio.channels.DatagramChannel
 
     val socket = DatagramChannel.open().socket()
-    socket.bind(new InetSocketAddress(hostname, 0))
-    val port = socket.getLocalPort
-    socket.close()
-    port
+    try {
+      socket.bind(new InetSocketAddress(hostname, 0))
+      socket.getLocalPort
+    } finally socket.close()

Review Comment:
   can also be used here:
   ```
     Using.resource(DatagramChannel.open().socket()) { socket =>
       socket.bind(new InetSocketAddress(hostname, 0))
       socket.getLocalPort
     }
   ```



##########
actor/src/main/scala/org/apache/pekko/io/dns/internal/ResolvConfParser.scala:
##########
@@ -33,7 +33,10 @@ private[dns] object ResolvConfParser {
    */
   def parseFile(file: File): Try[ResolvConf] = {
     Try {
-      parseLines(Files.lines(file.toPath).iterator().asScala)
+      // the stream holds the file open until closed, and parseLines consumes 
it eagerly
+      val lines = Files.lines(file.toPath)
+      try parseLines(lines.iterator().asScala)
+      finally lines.close()

Review Comment:
   Maybe use scala.util.Using?
   ```
       scala.util.Using(Files.lines(file.toPath)) { lines =>
         parseLines(lines.iterator().asScala)
       }
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to