Beware of execution queue in write callbacks
self.link was not checked against in tunnel queue.
This commit is contained in:
parent
6b281711c7
commit
de21adfef6
|
@ -1010,19 +1010,19 @@ 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
|
||||||
|
self?.queue.sync {
|
||||||
guard self?.link === writeLink else {
|
guard self?.link === writeLink else {
|
||||||
log.warning("Ignoring write from outdated LINK")
|
log.warning("Ignoring write from outdated LINK")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let error = error {
|
if let error = error {
|
||||||
self?.queue.sync {
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ruby: setup_keys
|
// Ruby: setup_keys
|
||||||
private func setupEncryption() {
|
private func setupEncryption() {
|
||||||
|
@ -1138,19 +1138,19 @@ 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
|
||||||
|
self?.queue.sync {
|
||||||
guard self?.link === writeLink else {
|
guard self?.link === writeLink else {
|
||||||
log.warning("Ignoring write from outdated LINK")
|
log.warning("Ignoring write from outdated LINK")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let error = error {
|
if let error = error {
|
||||||
self?.queue.sync {
|
|
||||||
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 {
|
||||||
deferStop(.shutdown, e)
|
deferStop(.shutdown, e)
|
||||||
|
@ -1184,20 +1184,20 @@ 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
|
||||||
|
self?.queue.sync {
|
||||||
guard self?.link === writeLink else {
|
guard self?.link === writeLink else {
|
||||||
log.warning("Ignoring write from outdated LINK")
|
log.warning("Ignoring write from outdated LINK")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let error = error {
|
if let error = error {
|
||||||
self?.queue.sync {
|
|
||||||
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)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Stop
|
// MARK: Stop
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue