             self._isWritable.store(localValue)
             self.pipeline.fireChannelWritabilityChanged()
         }
+    }
+}
+
+extension HTTP2StreamChannel {
+    // A helper function used to ensure that state modification leads to changes in the channel active atomic.
+    private func modifyingState<ReturnType>(_ closure: (inout StreamChannelState) throws -> ReturnType) rethrows -> ReturnType {
+        defer {
+            self._isActiveAtomic.store(self._isActive)
+        }
+        return try closure(&self.state)
     }
 }
 

            return
        }

        self.state.activate()
        self.pipeline.fireChannelActive()
        if self.autoRead {
            self.read0()

    public func flush0() {
        self.pendingWrites.mark()

        if self._isActive {
            self.deliverPendingWrites()
        }
    }
