         guard self.state != .closed else {
             return
         }
-        self.state.completeClosing()
+        self.modifyingState { $0.completeClosing() }
         self.dropPendingReads()
         self.failPendingWrites(error: error)
         if let promise = self.pendingClosePromise {


    private let _isWritable: NIOAtomic<Bool>

    public var isActive: Bool {
        return self.state == .active || self.state == .closing || self.state == .localActive
    }

    public var _channelCore: ChannelCore {
        return self

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

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