(&mut self, req: Request<B>)
| 346 | } |
| 347 | |
| 348 | fn call(&mut self, req: Request<B>) -> Self::Future { |
| 349 | // If `poll_ready` short-circuited an exhausted limiter, it never polled |
| 350 | // the inner service to readiness. Honor that decision regardless of the |
| 351 | // limiter's current state (the window may have rolled over since): the |
| 352 | // Tower contract forbids forwarding to an inner service that did not |
| 353 | // report readiness. |
| 354 | if std::mem::take(&mut self.rate_limited) { |
| 355 | let response = |
| 356 | tonic::Status::resource_exhausted("gRPC rate limit exceeded").into_http(); |
| 357 | return Box::pin(async move { Ok(response) }); |
| 358 | } |
| 359 | if self |
| 360 | .limiter |
| 361 | .as_ref() |
| 362 | .is_some_and(|limiter| !limiter.allow()) |
| 363 | { |
| 364 | let response = |
| 365 | tonic::Status::resource_exhausted("gRPC rate limit exceeded").into_http(); |
| 366 | return Box::pin(async move { Ok(response) }); |
| 367 | } |
| 368 | let future = self.inner.call(req); |
| 369 | Box::pin(future) |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /// Combined gRPC service that routes between `OpenShell` and Inference services |
no test coverage detected