Close dead connection in response to idle event from IdleStateHandler.
490101
@Override
  public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
      IdleStateEvent e = (IdleStateEvent) evt;
      if (e.state() == IdleState.READER_IDLE) {
        LOGGER.warn("Closing dead connection.");
        ctx.close();
        return;
      }
    }

    super.userEventTriggered(ctx, evt);
  }
710257
def __die(self, synchronous=False):
        
        if self.__id and not self.__killed:
            if self.__exhaust and self.__exhaust_mgr:
                # If this is an exhaust cursor and we haven't completely
                # exhausted the result set we *must* close the socket
                # to stop the server from sending more data.
                self.__exhaust_mgr.sock.close()
            else:
                address = _CursorAddress(
                    self.__address, self.__collection.full_name)
                if synchronous:
                    self.__collection.database.client._close_cursor_now(
                        self.__id, address)
                else:
                    self.__collection.database.client.close_cursor(
                        self.__id, address)
        if self.__exhaust and self.__exhaust_mgr:
            self.__exhaust_mgr.close()
        self.__killed = True
1014177
@Disconnect
    public void onDisconnect(AtmosphereResourceEvent event) {
        if (event.isCancelled()) {
            logger.info("Browser {} unexpectedly disconnected", event.getResource().uuid());
        } else if (event.isClosedByClient()) {
            logger.info("Browser {} closed the connection", event.getResource().uuid());
        }
    }
85256
def shutdown(self):
        """"""
        if self.OPEN:
            self.OPEN = False
            scoop.SHUTDOWN_REQUESTED = True
            self.socket.send(b"SHUTDOWN")
            self.socket.close()
            self.infoSocket.close()
            time.sleep(0.3)
672146
public void close() {
    if (zooKeeper != null) {
      try {
        zooKeeper.close();
      } catch (InterruptedException e) {
        LOG.error("Interrupt when closing zookeeper connection", e);
      }
    }
  }
976434
def close(self):
        """"""
        if not self.is_running:
            return

        self._state = CLOSED

        self.logger.debug('killing %d worker(s)', len(self._killables))
        self._killables.kill(block=False)

        self.logger.debug('closing %d connection(s)', len(self._connections))
        for conn in self._connections:
            conn.close_stream()

        self.on_close.send(self)
534191
public void shutdownAndWait() {
		try {
			client.shutdown().get();
			LOG.info("The Queryable State Client was shutdown successfully.");
		} catch (Exception e) {
			LOG.warn("The Queryable State Client shutdown failed: ", e);
		}
	}
688168
def mark_dead(self, connection, now=None):
        
        # allow inject for testing purposes
        now = now if now else time.time()
        try:
            self.connections.remove(connection)
        except ValueError:
            # connection not alive or another thread marked it already, ignore
            return
        else:
            dead_count = self.dead_count.get(connection, 0) + 1
            self.dead_count[connection] = dead_count
            timeout = self.dead_timeout * 2 ** min(dead_count - 1,
                                                   self.timeout_cutoff)
            self.dead.put((now + timeout, connection))
            logger.warning(
                'Connection %r has failed for %i times in a row,'
                ' putting on %i second timeout.',
                connection, dead_count, timeout
            )
1115920
def handle_quit(self, connection, event):
        
        nickname = self.get_nickname(event)
        self.quit[nickname] = datetime.now()
        del self.joined[nickname]
770559
def stop(self):
        """"""
        self._stop_thread.set()
        # f you want to close the connection in a timely fashion,
        # call shutdown() before close().
        with self._lock:  # Receive thread might use the socket
            self.receive_socket.shutdown(socket.SHUT_RDWR)
            self.receive_socket.close()

        self.send_socket.shutdown(socket.SHUT_RDWR)
        self.send_socket.close()
838341
def close(self):
        """"""
        self._lock.acquire()
        try:
            while self._idle_cache:  # close all idle connections
                con = self._idle_cache.pop(0)
                try:
                    con.close()
                except Exception:
                    pass
            if self._maxshared:  # close all shared connections
                while self._shared_cache:
                    con = self._shared_cache.pop(0).con
                    try:
                        con.close()
                    except Exception:
                        pass
                    self._connections -= 1
            self._lock.notifyAll()
        finally:
            self._lock.release()
1054012
def wait_until_idle(self):
        

        done = threading.Event()

        def _callback():
            done.set()

        self.defer_until_idle(_callback)
        done.wait()
654128
def disconnect(self):
        ""
        self._parser.on_disconnect()
        if self._sock is None:
            return
        if self._selector is not None:
            self._selector.close()
            self._selector = None
        try:
            if os.getpid() == self.pid:
                self._sock.shutdown(socket.SHUT_RDWR)
            self._sock.close()
        except socket.error:
            pass
        self._sock = None
676802
def purge(self, connection):
        """"""
        self._checkpid()
        if connection.pid == self.pid:
            idx = connection._pattern_idx
            if connection in self._in_use_connections[idx]:
                self._in_use_connections[idx].remove(connection)
            else:
                self._available_connections[idx].remove(connection)
            connection.disconnect()
1183296
def shutdown(self):
        """"""
        self.socket.shutdown()

        if scoop:
            if scoop.DEBUG:
                from scoop import _debug
                _debug.writeWorkerDebug(
                    scoop._control.debug_stats,
                    scoop._control.QueueLength,
                )
548656
def disconnect(self):
        '''
        
        '''
        if self._poll_stop_event:
            self._poll_stop_event.set()
        if self._driver:
            if self.status != 'idle':
                self.deactivate()
            self._driver.disconnect()
192151
def _socket_close(self):
        """"""
        callback = self.__callback
        self.__callback = None
        try:
            if callback:
                callback(None, InterfaceError('connection closed'))
        finally:
            # Flush the job queue, don't call the callbacks associated with the remaining jobs
            # since they have already been called as error callback on connection closing
            self.__job_queue = []
            self.__alive = False
            self.__pool.cache(self)