Beware of execution queue in write callbacks

self.link was not checked against in tunnel queue.
This commit is contained in:
Davide De Rosa 2019-08-12 15:18:39 +02:00
parent 6b281711c7
commit de21adfef6
1 changed files with 23 additions and 23 deletions

View File

@ -1010,16 +1010,16 @@ public class OpenVPNSession: Session {
// WARNING: runs in Network.framework queue // WARNING: runs in Network.framework queue
let writeLink = link let writeLink = link
link?.writePackets(rawList) { [weak self] (error) in link?.writePackets(rawList) { [weak self] (error) in
guard self?.link === writeLink else { self?.queue.sync {
log.warning("Ignoring write from outdated LINK") guard self?.link === writeLink else {
return log.warning("Ignoring write from outdated LINK")
} return
if let error = error { }
self?.queue.sync { if let error = error {
log.error("Failed LINK write during control flush: \(error)") log.error("Failed LINK write during control flush: \(error)")
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite) self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
return
} }
return
} }
} }
} }
@ -1138,18 +1138,18 @@ public class OpenVPNSession: Session {
controlChannel.addSentDataCount(encryptedPackets.flatCount) controlChannel.addSentDataCount(encryptedPackets.flatCount)
let writeLink = link let writeLink = link
link?.writePackets(encryptedPackets) { [weak self] (error) in link?.writePackets(encryptedPackets) { [weak self] (error) in
guard self?.link === writeLink else { self?.queue.sync {
log.warning("Ignoring write from outdated LINK") guard self?.link === writeLink else {
return log.warning("Ignoring write from outdated LINK")
} return
if let error = error { }
self?.queue.sync { if let error = error {
log.error("Data: Failed LINK write during send data: \(error)") log.error("Data: Failed LINK write during send data: \(error)")
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite) self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
return
} }
return // log.verbose("Data: \(encryptedPackets.count) packets successfully written to LINK")
} }
// log.verbose("Data: \(encryptedPackets.count) packets successfully written to LINK")
} }
} catch let e { } catch let e {
guard !e.isTunnelKitError() else { guard !e.isTunnelKitError() else {
@ -1184,18 +1184,18 @@ public class OpenVPNSession: Session {
// WARNING: runs in Network.framework queue // WARNING: runs in Network.framework queue
let writeLink = link let writeLink = link
link?.writePacket(raw) { [weak self] (error) in link?.writePacket(raw) { [weak self] (error) in
guard self?.link === writeLink else { self?.queue.sync {
log.warning("Ignoring write from outdated LINK") guard self?.link === writeLink else {
return log.warning("Ignoring write from outdated LINK")
} return
if let error = error { }
self?.queue.sync { if let error = error {
log.error("Failed LINK write during send ack for packetId \(controlPacket.packetId): \(error)") log.error("Failed LINK write during send ack for packetId \(controlPacket.packetId): \(error)")
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite) self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
return
} }
return log.debug("Ack successfully written to LINK for packetId \(controlPacket.packetId)")
} }
log.debug("Ack successfully written to LINK for packetId \(controlPacket.packetId)")
} }
} }