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

Method GracefulClose

internal/transport/http2_client.go:1088–1107  ·  view source on GitHub ↗

GracefulClose sets the state to draining, which prevents new streams from being created and causes the transport to be closed when the last active stream is closed. If there are no active streams, the transport is closed immediately. This does nothing if the transport is already draining or closin

()

Source from the content-addressed store, hash-verified

1086// immediately. This does nothing if the transport is already draining or
1087// closing.
1088func (t *http2Client) GracefulClose() {
1089 t.mu.Lock()
1090 // Make sure we move to draining only from active.
1091 if t.state == draining || t.state == closing {
1092 t.mu.Unlock()
1093 return
1094 }
1095 if t.logger.V(logLevel) {
1096 t.logger.Infof("GracefulClose called")
1097 }
1098 t.onClose(GoAwayInfo{Reason: GoAwayInvalid, GoAwayCode: http2.ErrCodeNo})
1099 t.state = draining
1100 active := len(t.activeStreams)
1101 t.mu.Unlock()
1102 if active == 0 {
1103 t.Close(connectionErrorf(true, nil, "no active streams left to process while draining"))
1104 return
1105 }
1106 t.controlBuf.put(&incomingGoAway{})
1107}
1108
1109// Write formats the data into HTTP2 data frame(s) and sends it out. The caller
1110// should proceed only if Write returns nil.

Callers 1

NewStreamMethod · 0.95

Calls 7

CloseMethod · 0.95
connectionErrorfFunction · 0.85
VMethod · 0.65
InfofMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected