MCPcopy
hub / github.com/grpc/grpc-go / stop

Method stop

server.go:1954–1996  ·  view source on GitHub ↗
(graceful bool)

Source from the content-addressed store, hash-verified

1952}
1953
1954func (s *Server) stop(graceful bool) {
1955 s.quit.Fire()
1956 defer s.done.Fire()
1957
1958 s.channelzRemoveOnce.Do(func() { channelz.RemoveEntry(s.channelz.ID) })
1959 s.mu.Lock()
1960 s.closeListenersLocked()
1961 // Wait for serving threads to be ready to exit. Only then can we be sure no
1962 // new conns will be created.
1963 s.mu.Unlock()
1964 s.serveWG.Wait()
1965
1966 s.mu.Lock()
1967 defer s.mu.Unlock()
1968
1969 if graceful {
1970 s.drainAllServerTransportsLocked()
1971 } else {
1972 s.closeServerTransportsLocked()
1973 }
1974
1975 for len(s.conns) != 0 {
1976 s.cv.Wait()
1977 }
1978 s.conns = nil
1979
1980 if s.opts.numServerWorkers > 0 {
1981 // Closing the channel (only once, via sync.OnceFunc) after all the
1982 // connections have been closed above ensures that there are no
1983 // goroutines executing the callback passed to st.HandleStreams (where
1984 // the channel is written to).
1985 s.serverWorkerChannelClose()
1986 }
1987
1988 if graceful || s.opts.waitForHandlers {
1989 s.handlersWG.Wait()
1990 }
1991
1992 if s.events != nil {
1993 s.events.Finish()
1994 s.events = nil
1995 }
1996}
1997
1998// s.mu must be held by the caller.
1999func (s *Server) closeServerTransportsLocked() {

Callers 2

StopMethod · 0.95
GracefulStopMethod · 0.95

Calls 10

closeListenersLockedMethod · 0.95
RemoveEntryFunction · 0.92
WaitMethod · 0.80
DoMethod · 0.65
FinishMethod · 0.65
FireMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected