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
()
| 1086 | // immediately. This does nothing if the transport is already draining or |
| 1087 | // closing. |
| 1088 | func (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. |