// Close closes the NATS connection after flushing what needed to be sent
191854
func (conn *Connection) Close() {
	subs := []string{}

	conn.subMu.Lock()

	for s := range conn.chanSubscriptions {
		subs = append(subs, s)
	}

	for s := range conn.subscriptions {
		subs = append(subs, s)
	}

	conn.subMu.Unlock()

	for _, s := range subs {
		err := conn.Unsubscribe(s)
		if err != nil {
			conn.logger.Warnf("Could not unsubscribe from %s: %s", s, err)
		}
	}


	conn.Flush()

	conn.conMu.Lock()
	defer conn.conMu.Unlock()

	conn.logger.Debug("Closing NATS connection")
	conn.nats.Close()
}
409893
func (ws *Conn) Close() error {
	err := ws.frameHandler.WriteClose(ws.defaultCloseStatus)
	if err != nil {
		return err
	}
	return ws.rwc.Close()
}
535254
func (c *Conn) Close() error {
	// Note that net.Conn.Close can be called multiple times and atomic store is
	// idempotent so no need to ensure we only do this once.
	//
	// Also note that we don't wait for CopyBytes to return here since we are
	// closing the conns which is the only externally visible sideeffect of that
	// goroutine running and there should be no way for it to hang or leak once
	// the conns are closed so we can save the extra coordination.
	atomic.StoreInt32(&c.stopping, 1)
	c.src.Close()
	c.dst.Close()
	return nil
}
1253339
func (n *NetNs) Close() error {
	if n == nil || n.netNS == nil {
		return nil
	}
	return n.netNS.Close()
}
753628
func (t *http2Server) Close() error {
	t.mu.Lock()
	if t.state == closing {
		t.mu.Unlock()
		return errors.New("transport: Close() was already called")
	}
	t.state = closing
	streams := t.activeStreams
	t.activeStreams = nil
	t.mu.Unlock()
	t.controlBuf.finish()
	t.cancel()
	err := t.conn.Close()
	if channelz.IsOn() {
		channelz.RemoveEntry(t.channelzID)
	}
	// Cancel all active streams.
	for _, s := range streams {
		s.cancel()
	}
	if t.stats != nil {
		connEnd := &stats.ConnEnd{}
		t.stats.HandleConn(t.ctx, connEnd)
	}
	return err
}
670794
func (b *Broker) Close() error {
	b.lock.Lock()
	defer b.lock.Unlock()

	if b.conn == nil {
		return ErrNotConnected
	}

	close(b.responses)
	<-b.done

	err := b.conn.Close()

	b.conn = nil
	b.connErr = nil
	b.done = nil
	b.responses = nil

	b.unregisterMetrics()

	if err == nil {
		Logger.Printf("Closed connection to broker %s\n", b.addr)
	} else {
		Logger.Printf("Error while closing connection to broker %s: %s\n", b.addr, err)
	}

	atomic.StoreInt32(&b.opened, 0)

	return err
}
785796
func (rb *respBody) Close() error {
	rb.conn.Close()
	return rb.ReadCloser.Close()
}
706777
func (c *Client) Close() error {
	c.connMu.Lock()
	defer c.connMu.Unlock()
	if c.conn != nil {
		return c.conn.Close()
	}
	return nil
}
1168428
func (conn *Conn) Close() error {
	<-conn.ready
	for _, s := range conn.channels {
		s.Close()
	}
	conn.ws.Close()
	return nil
}
1112071
func (c *SocketConnection) Close() error {
	if err := c.Conn.Close(); err != nil {
		return err
	}

	return nil
}
1240535
func (c *NamenodeConnection) Close() error {
	if c.conn != nil {
		return c.conn.Close()
	}
	return nil
}
1090837
func (h *packetHandlerMap) Close() error {
	if err := h.conn.Close(); err != nil {
		return err
	}
	<-h.listening // wait until listening returns
	return nil
}
1041788
func (c *Connector) Close() error {
	if c.Client != nil {
		return c.Close()
	}
	return nil
}
138435
func (c *Client) Close() error {
	c.Flush()
	c.close()
	return c.err
}
190319
func (c *Conn) Close() error {
	c.pipe.once.Do(func() {

		// Buffered connections will attempt to wait until all
		// pending Writes are completed or until the specified
		// timeout value has elapsed.
		if c.laddr.Buffered() {

			// Set up a channel that is closed when the specified
			// timer elapses.
			timeout := c.CloseTimeout()
			timeoutDone := make(chan struct{})
			if timeout == 0 {
				close(timeoutDone)
			} else {
				time.AfterFunc(timeout, func() { close(timeoutDone) })
			}

			// Set up a channel that is closed when there is
			// no more buffered data.
			writesDone := make(chan struct{})
			go func() {
				c.buf.dataMu.Lock()
				defer c.buf.dataMu.Unlock()
				for len(c.buf.dataN) > 0 {
					c.buf.dataMu.Unlock()
					c.buf.dataMu.Lock()
				}
				close(writesDone)
			}()

			// Wait to close the connection.
			select {
			case <-writesDone:
			case <-timeoutDone:
			}
		}

		close(c.pipe.localDone)
	})
	return nil
}
571943
func (p *PoolConn) Close() error {
	p.mu.RLock()
	defer p.mu.RUnlock()

	if p.unusable {
		if p.Conn != nil {
			return p.Conn.Close()
		}
		return nil
	}
	return p.c.put(p.Conn)
}
1041009
func (sc *conn) cleanupOnClose(err error) {
	sc.pingMu.Lock()
	if sc.pingTimer != nil {
		sc.pingTimer.Stop()
		sc.pingTimer = nil
	}
	sc.pingMu.Unlock()

	// Unsubscribe only if the NATS connection is not already closed
	// and we don't own it (otherwise connection is going to be closed
	// so no need for explicit unsubscribe).
	if !sc.ncOwned && !sc.nc.IsClosed() {
		if sc.hbSubscription != nil {
			sc.hbSubscription.Unsubscribe()
		}
		if sc.pingSub != nil {
			sc.pingSub.Unsubscribe()
		}
		if sc.ackSubscription != nil {
			sc.ackSubscription.Unsubscribe()
		}
	}
	// Fail all pending pubs
	for guid, pubAck := range sc.pubAckMap {
		if pubAck.t != nil {
			pubAck.t.Stop()
		}
		if pubAck.ah != nil {
			pubAck.ah(guid, err)
		} else if pubAck.ch != nil {
			pubAck.ch <- err
		}
		delete(sc.pubAckMap, guid)
		if len(sc.pubAckChan) > 0 {
			<-sc.pubAckChan
		}
	}
}