(ctx context.Context, rpcStats stats.RPCStats)
| 153 | } |
| 154 | |
| 155 | func (g *grpcInflightLimitCheck) HandleRPC(ctx context.Context, rpcStats stats.RPCStats) { |
| 156 | switch rpcStats.(type) { |
| 157 | case *stats.InHeader: |
| 158 | if state, ok := ctx.Value(gprcInflightLimitCheckerStateKey{}).(*gprcInflightLimitCheckerState); ok { |
| 159 | // We're processing this request, stop the timer. |
| 160 | if !state.nonProcessedRequestTimer.Stop() { |
| 161 | level.Warn(state.logger(g.logger)).Log("msg", "gRPC request processing has started, but the non-processing timer already fired, need to signal that we're processing it now") |
| 162 | // The timer has already expired, so the function is either executing or has executed. |
| 163 | // |
| 164 | // This (stats.InHeader) should be called once and only once, but gRPC is known for changing contracts |
| 165 | // and we don't want this to start panicking trying to close the channel multiple times, |
| 166 | // so a sync.Once doesn't hurt here. |
| 167 | state.headersProcessedOnce.Do(func() { close(state.headersProcessed) }) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | case *stats.End: |
| 172 | if state, ok := ctx.Value(gprcInflightLimitCheckerStateKey{}).(*gprcInflightLimitCheckerState); ok { |
| 173 | // We're done processing the request, but there's a scenario under which we may have already called RPCCallFinished, |
| 174 | // from the goroutine watching the context in TapHandle, so we need to ensure it's called only once. |
| 175 | called := false |
| 176 | state.rpcCallFinishedOnce.Do(func() { |
| 177 | g.methodLimiter.RPCCallFinished(ctx) |
| 178 | called = true |
| 179 | }) |
| 180 | if !called { |
| 181 | level.Warn(state.logger(g.logger)).Log("msg", "RPCCallFinished was already called for this gRPC request before the request actually finished processing") |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | func (g *grpcInflightLimitCheck) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context { |
| 188 | return ctx |
nothing calls this directly
no test coverage detected