// Close closes the backend.
// Note that this closes the backend one-way (gateway to backend).
// This makes it possible to perform a graceful shutdown (e.g. when there are
// still packets to send back to the gateway).
167986
func (b *Backend) Close() error {
	log.Info("gateway/mqtt: closing backend")

	log.WithField("topic", b.eventTopic).Info("gateway/mqtt: unsubscribing from event topic")
	if token := b.conn.Unsubscribe(b.eventTopic); token.Wait() && token.Error() != nil {
		return fmt.Errorf("gateway/mqtt: unsubscribe from %s error: %s", b.eventTopic, token.Error())
	}

	log.Info("backend/gateway: handling last messages")
	b.wg.Wait()
	close(b.rxPacketChan)
	close(b.statsPacketChan)
	close(b.downlinkTXAckChan)
	return nil
}
842418
func (p *Proxy) Close() {
	close(p.stopChan)
	if p.service != nil {
		p.service.Close()
	}
}
389096
func (srv *Server) Close() error {
	srv.mu.Lock()
	defer srv.mu.Unlock()
	srv.closeDoneChanLocked()
	err := srv.closeListenersLocked()
	for c := range srv.conns {
		c.Close()
		delete(srv.conns, c)
	}
	return err
}
706777
func (c *Client) Close() error {
	c.connMu.Lock()
	defer c.connMu.Unlock()
	if c.conn != nil {
		return c.conn.Close()
	}
	return nil
}
191731
func (f *Pub) Close() error {
	f.wo.Lock()
	ok := f.closed
	f.wo.Unlock()

	if ok {
		return nil
	}

	f.wg.Wait()

	f.wo.Lock()
	f.closed = true
	f.wo.Unlock()

	f.branches.Close()

	f.roots.Do(func(rm SenderDetachCloser) {
		go rm.Detach(f)
	})

	f.roots.Close()
	f.enders.Close()

	close(f.csignal)
	return nil
}
471540
func (b SqlAuthBackend) Close() {
	b.db.Close()
	b.userStmt.Close()
	b.usersStmt.Close()
	b.insertStmt.Close()
	b.updateStmt.Close()
	b.deleteStmt.Close()
}
462148
func (client Client) Close() error {
	err := client.Sender.Close()
	return errors.Trace(err)
}
618880
func (s *WebSocketServer) Close() error {
	s.tomb.Kill(errManualClose)

	err := s.listener.Close()
	_ = s.tomb.Wait()

	if err != nil {
		return err
	}

	return nil
}
635084
func (s *Server) Close() {
	close(s.closing)
	s.listener.Close()
	// We need to remove the socket path because
	// we renamed the path after opening the
	// socket and it won't be cleaned up automatically.
	// Ignore error as we can't do much here
	// anyway and remove the path if we start the
	// server again.
	os.Remove(s.socketPath)
	<-s.closed
}
955856
func (connector *Forwarder) Close() error {
	connector.tr.CloseIdleConnections()
	return connector.sampler.Close()
}
1295945
func (rw *Response) Close() error {
	defer rw.closedLock.Unlock()

	if rw.body != nil {
		return rw.body.Close()
	}
	return nil
}
565296
func (b *DynamoDBBackend) Close() error {
	b.setClosed()
	b.cancel()
	return b.buf.Close()
}
998314
func (c *Client) Close() error {
	c.closedLock.Lock()
	defer c.closedLock.Unlock()

	if c.closed {
		return nil
	}
	c.closed = true
	c.client.GoAway() // Notify the other side of the close
	return c.client.Close()
}
390104
func (s *SocketHub) Close() {
	if s.closed {
		return
	}
	s.closed = true
	close(s.closer)
}
1312792
func (f *Forwarder) Close() error {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.file.Close()
}
251618
func (s *Server) Close() {
	if atomic.CompareAndSwapInt64(&s.closed, 0, 1) {
		s.lck.Lock()
		defer s.lck.Unlock()
		close(s.closeSig)
		s.srv.Close()
		s.srv.CloseClientConnections()
		return
	}
}
1324865
func (ch *Channel) Close() error {
	ch.once.Do(func() {
		close(ch.closed)
	})

	return nil
}