@@ -19,14 +19,12 @@ use quinn_proto::{PathError, PathEvent, PathId, PathStatus};
1919use rustc_hash:: FxHashMap ;
2020use smallvec:: SmallVec ;
2121use sync_wrapper:: SyncStream ;
22- use tokio:: sync:: oneshot;
2322use tokio_stream:: wrappers:: { BroadcastStream , errors:: BroadcastStreamRecvError } ;
2423use tracing:: { Instrument , Level , debug, error, event, info_span, instrument, trace, warn} ;
2524
26- use self :: {
27- guarded_channel:: { GuardedReceiver , GuardedSender , guarded_channel} ,
28- path_state:: RemotePathState ,
29- } ;
25+ use self :: path_state:: RemotePathState ;
26+ use tokio:: sync:: { mpsc, oneshot} ;
27+
3028use super :: Source ;
3129use crate :: {
3230 disco:: { self } ,
@@ -41,7 +39,6 @@ use crate::{
4139 util:: MaybeFuture ,
4240} ;
4341
44- pub ( crate ) mod guarded_channel;
4542mod path_state;
4643
4744// TODO: use this
@@ -212,8 +209,8 @@ impl RemoteStateActor {
212209 pub ( super ) fn start (
213210 self ,
214211 tasks : & mut JoinSet < Vec < RemoteStateMessage > > ,
215- ) -> GuardedSender < RemoteStateMessage > {
216- let ( tx, rx) = guarded_channel ( 16 ) ;
212+ ) -> mpsc :: Sender < RemoteStateMessage > {
213+ let ( tx, rx) = mpsc :: channel ( 16 ) ;
217214 let me = self . local_endpoint_id ;
218215 let endpoint_id = self . endpoint_id ;
219216
@@ -238,7 +235,7 @@ impl RemoteStateActor {
238235 /// discipline is needed to not turn pending for a long time.
239236 async fn run (
240237 mut self ,
241- mut inbox : GuardedReceiver < RemoteStateMessage > ,
238+ mut inbox : mpsc :: Receiver < RemoteStateMessage > ,
242239 ) -> Vec < RemoteStateMessage > {
243240 trace ! ( "actor started" ) ;
244241 let idle_timeout = time:: sleep ( ACTOR_MAX_IDLE_TIMEOUT ) ;
@@ -254,7 +251,7 @@ impl RemoteStateActor {
254251 None => MaybeFuture :: None ,
255252 } ;
256253 n0_future:: pin!( scheduled_hp) ;
257- if !inbox. is_idle ( ) || !self . connections . is_empty ( ) {
254+ if !inbox. is_empty ( ) || !self . connections . is_empty ( ) {
258255 idle_timeout
259256 . as_mut ( )
260257 . reset ( Instant :: now ( ) + ACTOR_MAX_IDLE_TIMEOUT ) ;
@@ -298,16 +295,22 @@ impl RemoteStateActor {
298295 self . handle_discovery_item( item) ;
299296 }
300297 _ = & mut idle_timeout => {
301- if self . connections. is_empty( ) && inbox. close_if_idle ( ) {
298+ if self . connections. is_empty( ) && inbox. is_empty ( ) {
302299 trace!( "idle timeout expired and still idle: terminate actor" ) ;
303- break vec![ ] ;
300+ inbox. close( ) ;
301+ // There might be a race between checking `inbox.is_empty()` and `inbox.close()`,
302+ // so we pull out all messages that are left over.
303+ let mut leftover_msgs = Vec :: with_capacity( inbox. len( ) ) ;
304+ inbox. recv_many( & mut leftover_msgs, inbox. len( ) ) . await ;
305+ break leftover_msgs;
304306 } else {
305307 // Seems like we weren't really idle, so we reset
306308 idle_timeout. as_mut( ) . reset( Instant :: now( ) + ACTOR_MAX_IDLE_TIMEOUT ) ;
307309 }
308310 }
309311 }
310312 } ;
313+
311314 trace ! ( "actor terminating" ) ;
312315 leftover_msgs
313316 }
0 commit comments