Ensure that we fire channelActive and channelInactive in order (#373)

Motivation:

channelActive must always precede channelInactive. Unfortunately, this
isn't guaranteed right now: if we happen to get channelInactive as a
result of our writing the preamble we'll fire them in the wrong order.
Many systems can tolerate this, but we should avoid doing this anyway.

Modifications:

- Added a state enum to keep track of the state we're in
- Use that state enum to ensure we deliver active/inactive in the right
  order
- Additionally police other unexpected active/inactive behaviours

Result:

We'll appropriately police the state.
This commit is contained in:
Cory Benfield authored and GitHub committed 2023-02-15 15:52:34 +00:00
1 parent 5fcdf62ae8
commit 8dcda68288
6 files changed
+370 -6

No files matched your search

+19
View File
@@ -1622,6 +1622,25 @@ public enum NIOHTTP2Errors {
self.storage = .init(streamID: streamID, baseError: baseError)
}
}
public struct ActivationError: NIOHTTP2Error, CustomStringConvertible {
private let state: NIOHTTP2Handler.ActivationState
private var activating: Bool
init(state: NIOHTTP2Handler.ActivationState, activating: Bool) {
self.state = state
self.activating = activating
}
public var description: String {
if self.activating {
return "Error during activation: in state \(self.state)"
} else {
return "Error during inactivation: in state \(self.state)"
}
}
}
}