@@ -98,7 +98,7 @@ impl<T> Queue<T> {
98
98
/// `Option`, to represent the object not being found.
99
99
pub fn spawn_monitor < ID , S , E , Res : Send + ' static > (
100
100
service : S ,
101
- response_sender : mpsc:: Sender < ( ID , Res ) > ,
101
+ response_sender : mpsc:: UnboundedSender < ( ID , Res ) > ,
102
102
logger : Logger ,
103
103
metrics : PollingMonitorMetrics ,
104
104
) -> PollingMonitor < ID >
@@ -149,10 +149,13 @@ where
149
149
let mut backoffs = Backoffs :: new ( ) ;
150
150
let mut responses = service. call_all ( queue_to_stream) . unordered ( ) . boxed ( ) ;
151
151
while let Some ( response) = responses. next ( ) . await {
152
+ // Note: Be careful not to `await` within this loop, as that could block requests in
153
+ // the `CallAll` from being polled. This can cause starvation as those requests may
154
+ // be holding on to resources such as slots for concurrent calls.
152
155
match response {
153
156
Ok ( ( id, Some ( response) ) ) => {
154
157
backoffs. remove ( & id) ;
155
- let send_result = response_sender. send ( ( id, response) ) . await ;
158
+ let send_result = response_sender. send ( ( id, response) ) ;
156
159
if send_result. is_err ( ) {
157
160
// The receiver has been dropped, cancel this task.
158
161
break ;
@@ -250,10 +253,10 @@ mod tests {
250
253
fn setup ( ) -> (
251
254
mock:: Handle < & ' static str , Option < & ' static str > > ,
252
255
PollingMonitor < & ' static str > ,
253
- mpsc:: Receiver < ( & ' static str , & ' static str ) > ,
256
+ mpsc:: UnboundedReceiver < ( & ' static str , & ' static str ) > ,
254
257
) {
255
258
let ( svc, handle) = mock:: pair ( ) ;
256
- let ( tx, rx) = mpsc:: channel ( 10 ) ;
259
+ let ( tx, rx) = mpsc:: unbounded_channel ( ) ;
257
260
let monitor = spawn_monitor ( svc, tx, log:: discard ( ) , PollingMonitorMetrics :: mock ( ) ) ;
258
261
( handle, monitor, rx)
259
262
}
@@ -263,7 +266,7 @@ mod tests {
263
266
let ( svc, mut handle) = mock:: pair ( ) ;
264
267
let shared_svc = tower:: buffer:: Buffer :: new ( tower:: limit:: ConcurrencyLimit :: new ( svc, 1 ) , 1 ) ;
265
268
let make_monitor = |svc| {
266
- let ( tx, rx) = mpsc:: channel ( 10 ) ;
269
+ let ( tx, rx) = mpsc:: unbounded_channel ( ) ;
267
270
let metrics = PollingMonitorMetrics :: mock ( ) ;
268
271
let monitor = spawn_monitor ( svc, tx, log:: discard ( ) , metrics) ;
269
272
( monitor, rx)
0 commit comments