// Try to perform a graceful stop of the gRPC server.  If it takes more than
// 10 seconds, timeout and force-stop.
331128
func (p *Proxy) gRPCStop() {
	if p.grpcServer == nil {
		return
	}

	done := make(chan struct{})
	go func() {
		p.grpcServer.GracefulStop()
		close(done)
	}()

	select {
	case <-done:
		return
	case <-time.After(10 * time.Second):
		log.Info("Force-stopping the gRPC server after waiting for a graceful shutdown")
		p.grpcServer.Stop()
	}
}
361021
func (c *CheckHTTP) Stop() {
	c.stopLock.Lock()
	defer c.stopLock.Unlock()
	if !c.stop {
		c.stop = true
		close(c.stopCh)
	}
}
115310
func (t *Transport) Stop() error {
	return t.once.Stop(func() error {
		t.lock.Lock()
		defer t.lock.Unlock()
		for _, grpcPeer := range t.addressToPeer {
			grpcPeer.stop()
		}
		var err error
		for _, grpcPeer := range t.addressToPeer {
			err = multierr.Append(err, grpcPeer.wait())
		}
		return err
	})
}
1076921
func (s *Server) Stop() {
	s.grpcServer.Stop()
	for i := len(s.plugins) - 1; i >= 0; i-- {
		p := s.plugins[i]
		instance, err := p.Instance()
		if err != nil {
			log.L.WithError(err).WithField("id", p.Registration.ID).
				Errorf("could not get plugin instance")
			continue
		}
		closer, ok := instance.(io.Closer)
		if !ok {
			continue
		}
		if err := closer.Close(); err != nil {
			log.L.WithError(err).WithField("id", p.Registration.ID).
				Errorf("failed to close plugin")
		}
	}
}
156733
func (m *MockEndorserServer) Stop() {
	if m.srv == nil {
		panic("MockBroadcastServer not started")
	}

	m.srv.Stop()
	m.wg.Wait()
	m.srv = nil
}
1255668
func (s *Server) Stop() error {
	s.mu.Lock()

	if !s.isRunning() {
		s.mu.Unlock()
		return errors.New("CA signer is already stopped")
	}
	s.cancel()
	s.started = make(chan struct{})
	s.joinTokens = nil
	s.mu.Unlock()

	// Wait for Run to complete
	s.wg.Wait()

	return nil
}
1274439
func Try(fun func(), handler func(interface{})) {
	defer func() {
		if err := recover(); err != nil {
			handler(err)
		}
	}()
	fun()
}
239138
func (c *Client) Stop() {
	if c.clientStopChan == nil {
		panic("gorpc.Client: the client must be started before stopping it")
	}
	close(c.clientStopChan)
	c.stopWg.Wait()
	c.clientStopChan = nil
}
209886
func (s *Server) Stop() {
	s.quitOnce.Do(func() {
		close(s.quit)
	})

	defer func() {
		s.serveWG.Wait()
		s.doneOnce.Do(func() {
			close(s.done)
		})
	}()

	s.channelzRemoveOnce.Do(func() {
		if channelz.IsOn() {
			channelz.RemoveEntry(s.channelzID)
		}
	})

	s.mu.Lock()
	listeners := s.lis
	s.lis = nil
	st := s.conns
	s.conns = nil
	// interrupt GracefulStop if Stop and GracefulStop are called concurrently.
	s.cv.Broadcast()
	s.mu.Unlock()

	for lis := range listeners {
		lis.Close()
	}
	for c := range st {
		c.Close()
	}

	s.mu.Lock()
	if s.events != nil {
		s.events.Finish()
		s.events = nil
	}
	s.mu.Unlock()
}
866502
func (s *Server) Stop() {
	s.stopOnce.Do(func() {
		s.stopped = true
		s.listener.Close()
		close(s.startCh)
	})
}
1167369
func (p *Proxy) Shutdown() {
	log.Info("Shutting down server gracefully")
	close(p.shutdown)
	graceful.Shutdown()
	p.gRPCStop()
}
70116
func Stop() {
	if dispatcher == nil {
		return
	}
	if err := dispatcher.Stop(); err != nil {
		log.Println("oneway server dispatcher failed to stop:", err.Error())
	}
}
1368419
func (p *gateway) stop(ctx context.Context) (err error) {
	startTime := p.tk.Now() // keeps track of the time when graceful shutdown began
	p.logger.Log("Starting graceful shutdown")

	errs := make([]error, len(p.listeners)+len(p.forwarders)+1)

	// close health checks on all first
	closeListenerHealthChecks(p.listeners)

	// create timeout context for graceful shutdown period
	timeout, cancel := context.WithTimeout(GetContext(ctx), *p.config.MaxGracefulWaitTimeDuration) // max graceful timeout context
	defer cancel()

	// wait for forwarder pipeline to drain
	p.waitForForwardersToDrain(timeout, startTime)

	// close listeners
	p.logger.Log("Close listeners")
	listenErrs := closeListeners(p.listeners)
	log.IfErr(p.logger, errors.NewMultiErr(listenErrs))
	errs = append(errs, listenErrs...)

	// close forwarders
	p.logger.Log("Close forwarders")
	fwdErrs := closeForwarders(p.forwarders)
	log.IfErr(p.logger, errors.NewMultiErr(fwdErrs))
	errs = append(errs, fwdErrs...)

	// Stop the etcd server using the timeout context from above for graceful shutdown
	// If the context is already expired it will do a hard stop of the etcd server.
	// if there is time left on the timeout it will attempt a graceful shutdown.
	// etcd should not be stopped until all forwarders have been stopped
	if p.etcdServer != nil && p.etcdServer.IsRunning() {
		errs = append(errs, p.etcdServer.Shutdown(timeout))
	}

	// The graceful part of shutdown is complete when all of the inflight pipeline is cleared and the
	// etcd server is shutdown.  Log whether we made it here before the graceful shutdown context timedout
	logIfCtxExceeded(ctx, p.logger)

	// close the etcd client if it is not nil
	if p.etcdClient != nil {
		errs = append(errs, p.etcdClient.Close())
	}

	// stop debug server listener
	if p.debugServer != nil {
		errs = append(errs, p.debugServerListener.Close())
	}

	// stop internal metric server listener
	if p.internalMetricsServer != nil {
		errs = append(errs, p.internalMetricsListener.Close())
	}

	// remove the pid file
	removePidFile(p.config, p.logger)

	return errors.NewMultiErr(errs)
}
639365
func (srv *Server) Stop() {
	srv.lock.Lock()
	if !srv.running {
		srv.lock.Unlock()
		return
	}
	srv.running = false
	if srv.listener != nil {
		// this unblocks listener Accept
		srv.listener.Close()
	}
	close(srv.quit)
	srv.lock.Unlock()
	srv.loopWG.Wait()
}
61294
func (fw *JSONRPC) Stop(ctx context.Context, info map[string]string) (bool, error) {
	err := fw.makeRpcRequest(ctx, "Stop", info, 0)
	return err == nil, err
}
652523
func (s *server) Stop() {
	if s.State() == Stopped {
		return
	}

	close(s.stopped)

	// make sure all goroutines have stopped before we close the log
	s.routineGroup.Wait()

	s.log.close()
	s.setState(Stopped)
}
933698
func (p *Project) StopWithTimeout(c *check.C, containerID string, timeout int) {
	c.Assert(p.project.StopWithTimeout(containerID, timeout), check.IsNil,
		check.Commentf("error while stopping container %s with timeout %d", containerID, timeout))
}