@@ -277,46 +277,42 @@ where
277277 }
278278
279279 async fn check_end_of_resend ( & mut self ) -> Result < ( ) , SessionOperationError > {
280- let backlog = if let SessionState :: AwaitingResend ( state) = & mut self . state {
281- if self . ctx . store . next_target_seq_number ( ) > state. end_seq_number {
282- let inbound_queue = std:: mem:: take ( & mut state. inbound_queue ) ;
283- let new_state = SessionState :: new_active (
284- state. writer . clone ( ) ,
285- self . ctx . config . heartbeat_interval ,
286- ) ;
287- self . apply_transition ( TransitionResult :: TransitionTo ( new_state) )
288- . await ;
289- Some ( inbound_queue)
290- } else {
291- None
292- }
280+ let completed = if let SessionState :: AwaitingResend ( state) = & mut self . state {
281+ state. try_complete (
282+ self . ctx . store . next_target_seq_number ( ) ,
283+ self . ctx . config . heartbeat_interval ,
284+ )
293285 } else {
294286 None
295287 } ;
296288
297- if let Some ( mut inbound_queue) = backlog {
298- // we have reached the end of the resend,
299- // process queued messages and resume normal operation
300- debug ! ( "resend is done, processing backlog" ) ;
301- while let Some ( msg) = inbound_queue. pop_front ( ) {
302- let seq_number: u64 = msg. get ( MSG_SEQ_NUM ) . unwrap_or_else ( |e| {
303- error ! ( "failed to get seq number: {:?}" , e) ;
304- 0
305- } ) ;
306- let msg_type: & str = msg. header ( ) . get ( MSG_TYPE ) . unwrap_or ( "" ) ;
307- debug ! ( seq_number, msg_type, "processing queued message" ) ;
308-
309- if msg_type == ResendRequest :: MSG_TYPE {
310- // ResendRequest was already processed when it arrived (it bypasses
311- // the queue in process_message). Just increment the target seq number
312- // for sequence accounting purposes.
313- self . ctx . store . increment_target_seq_number ( ) . await ?;
314- } else {
315- self . process_message ( msg) . await ?;
316- }
289+ let Some ( ( new_state, mut backlog) ) = completed else {
290+ return Ok ( ( ) ) ;
291+ } ;
292+
293+ self . apply_transition ( TransitionResult :: TransitionTo ( new_state) )
294+ . await ;
295+
296+ // Process queued messages and resume normal operation
297+ debug ! ( "resend is done, processing backlog" ) ;
298+ while let Some ( msg) = backlog. pop_front ( ) {
299+ let seq_number: u64 = msg. get ( MSG_SEQ_NUM ) . unwrap_or_else ( |e| {
300+ error ! ( "failed to get seq number: {:?}" , e) ;
301+ 0
302+ } ) ;
303+ let msg_type: & str = msg. header ( ) . get ( MSG_TYPE ) . unwrap_or ( "" ) ;
304+ debug ! ( seq_number, msg_type, "processing queued message" ) ;
305+
306+ if msg_type == ResendRequest :: MSG_TYPE {
307+ // ResendRequest was already processed when it arrived (it bypasses
308+ // the queue in process_message). Just increment the target seq number
309+ // for sequence accounting purposes.
310+ self . ctx . store . increment_target_seq_number ( ) . await ?;
311+ } else {
312+ self . process_message ( msg) . await ?;
317313 }
318- debug ! ( "resend backlog is cleared, resuming normal operation" ) ;
319314 }
315+ debug ! ( "resend backlog is cleared, resuming normal operation" ) ;
320316
321317 Ok ( ( ) )
322318 }
0 commit comments