From 0feb182dd1fdc166ef1f5c7d22f508991b5c5177 Mon Sep 17 00:00:00 2001 From: Matt Klein Date: Fri, 10 Jun 2022 11:52:39 -0600 Subject: [PATCH] service: clarify docs around shared resource consumption in poll_ready() (#662) Signed-off-by: Matt Klein --- tower-service/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tower-service/src/lib.rs b/tower-service/src/lib.rs index c2f531e1a..a6ef0ecec 100644 --- a/tower-service/src/lib.rs +++ b/tower-service/src/lib.rs @@ -331,6 +331,12 @@ pub trait Service { /// Once `poll_ready` returns `Poll::Ready(Ok(()))`, a request may be dispatched to the /// service using `call`. Until a request is dispatched, repeated calls to /// `poll_ready` must return either `Poll::Ready(Ok(()))` or `Poll::Ready(Err(_))`. + /// + /// Note that `poll_ready` may reserve shared resources that are consumed in a subsequent + /// invocation of `call`. Thus, it is critical for implementations to not assume that `call` + /// will always be invoked and to ensure that such resources are released if the service is + /// dropped before `call` is invoked or the future returned by `call` is dropped before it + /// is polled. fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll>; /// Process the request and return the response asynchronously.