apple / swift-nio-http2

HTTP/2 support for SwiftNIO

Home Page:https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suppress writes triggered by EOF reads

Lukasa opened this issue · comments

When a child channel is "closed while open", we deliver any pending reads into the Channel:

if self.pendingReads.count > 0 && self._isActive {
self.unsatisfiedRead = false
self.deliverPendingReads()
}

After that, we actually close the stream:

if let reason = reason {
// To receive from the network, it must be safe to force-unwrap here.
let err = NIOHTTP2Errors.streamClosed(streamID: self.streamID!, errorCode: reason)
self.errorEncountered(error: err)
} else {
self.closedCleanly()
}

The problem with this is that these reads may trigger some writes. Those writes are doomed to fail, but we let them run into the parent channel before they fail. We could fail them faster by making the stream channel state a little more complex. This will also prevent errors triggered by these writes from having to propagate through the parent channel, which can trigger weird follow-on issues.