From fc3872abe67868dafb90f68cae9d937a95f2e59f Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 5 Oct 2021 01:31:42 -0700 Subject: [PATCH] Partially revert "Merge pull request #2644 from stephennancekivell/fix/GH-2643-socket-leak" This partially reverts commit 271f8b8aff30908f01e837a359f950171899fec4, reversing changes made to f92941b2265014478385a2c54846de680c134689. --- io/jvm/src/main/scala/fs2/io/net/SocketPlatform.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/jvm/src/main/scala/fs2/io/net/SocketPlatform.scala b/io/jvm/src/main/scala/fs2/io/net/SocketPlatform.scala index 9f4315c876..584df4d2d9 100644 --- a/io/jvm/src/main/scala/fs2/io/net/SocketPlatform.scala +++ b/io/jvm/src/main/scala/fs2/io/net/SocketPlatform.scala @@ -36,11 +36,11 @@ private[net] trait SocketCompanionPlatform { private[net] def forAsync[F[_]: Async]( ch: AsynchronousSocketChannel ): Resource[F, Socket[F]] = - Resource.eval { + Resource.make { (Semaphore[F](1), Semaphore[F](1)).mapN { (readSemaphore, writeSemaphore) => new AsyncSocket[F](ch, readSemaphore, writeSemaphore) } - } + }(_ => Async[F].delay(if (ch.isOpen) ch.close else ())) private[net] abstract class BufferedReads[F[_]]( readSemaphore: Semaphore[F]