From 83def0a52be8abc5b60a579698bca1a27c21853f Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 24 Sep 2018 03:08:18 +0200 Subject: [PATCH] Prevent signal and wait from racing Signed-off-by: Jason A. Donenfeld --- WireGuardNetworkExtension/PacketTunnelProvider.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index 9959dec..e884b8f 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -181,7 +181,7 @@ class WireGuardContext { private var packetFlow: NEPacketTunnelFlow private var outboundPackets: [NEPacket] = [] private var isTunnelClosed: Bool = false - private let readPacketCondition = NSCondition() + private var readPacketCondition = NSCondition() init(packetFlow: NEPacketTunnelFlow) { self.packetFlow = packetFlow @@ -193,7 +193,9 @@ class WireGuardContext { } func packetsRead(packets: [NEPacket]) { + readPacketCondition.lock() outboundPackets.append(contentsOf: packets) + readPacketCondition.unlock() readPacketCondition.signal() }