                         if ev.isReadable {
                             channel.readFromEventLoop()
                             
-                            guard channel.open else {
-                                safeDeregister(channel: channel)
+                            guard handleEvents(channel) else {
                                 continue
                             }
                         }
                         
+                        // Ensure we never reach here if the channel is not open anymore.
                         assert(channel.open)
-                        assert(ev.isReadable || ev.isWritable)
-                    
                     } else if ev.selectable is ServerSocket {
                         let socket = ev.selectable as! ServerSocket
                         

            
        return promise.futureResult
    }
    
    
    private func safeDeregister(channel: Channel) {
        do {
            try deregister(channel: channel)
        } catch {
            // ignore
        }
    }
    
    public func run(initPipeline: (ChannelPipeline) throws -> ()) throws {
        thread = Thread.current
        

                for ev in events {
                    if ev.selectable is Socket {
                        let channel = ev.attachment as! Channel

                        guard handleEvents(channel) else {
                            continue
                        }

                        if ev.isWritable {
                            channel.flushFromEventLoop()
                            
                            guard handleEvents(channel) else {
                                continue
                            }
                        }
