         #if os(Linux)
             shutdown(socket, Int32(SHUT_RDWR))
         #else
-            Darwin.shutdown(socket, SHUT_RDWR)
+            let _ = Darwin.shutdown(socket, SHUT_RDWR)
         #endif
     }
     
     private class func release(_ socket: Int32) {
         #if os(Linux)
             shutdown(socket, Int32(SHUT_RDWR))
-        #else
-            Darwin.shutdown(socket, SHUT_RDWR)
-        #endif
-        close(socket)
+            close(socket)
+        #else
+            if Darwin.shutdown(socket, SHUT_RDWR) != -1 {
+                // If you close socket which was already closed it produces exception visible in TestFlight's crash log.
+                // This is easily can be fixed by checking result on shutdown function != -1.
+                close(socket)
+            }
+        #endif
     }
     
     private class func htonsPort(_ port: in_port_t) -> in_port_t {

}

public class Socket: Hashable, Equatable {
    

    
    public class func tcpSocketForListen(_ port: in_port_t, forceIPv4: Bool = false, maxPendingConnection: Int32 = SOMAXCONN) throws -> Socket {


        return Socket(socketFileDescriptor: socketFileDescriptor)
    }
    
    internal let socketFileDescriptor: Int32
    
    public init(socketFileDescriptor: Int32) {
        self.socketFileDescriptor = socketFileDescriptor
