@@ -1118,14 +1118,15 @@ where
11181118 None => { } ,
11191119 }
11201120
1121- let mut futures = Joiner :: new ( ) ;
1122-
11231121 // We capture pending_operation_count inside the persistence branch to
11241122 // avoid a race: ChannelManager handlers queue deferred monitor ops
11251123 // before the persistence flag is set. Capturing outside would let us
11261124 // observe pending ops while the flag is still unset, causing us to
11271125 // flush monitor writes without persisting the ChannelManager.
1128- let mut pending_monitor_writes = 0 ;
1126+ // Declared before futures so it outlives the Joiner (drop order).
1127+ let pending_monitor_writes;
1128+
1129+ let mut futures = Joiner :: new ( ) ;
11291130
11301131 if channel_manager. get_cm ( ) . get_and_clear_needs_persistence ( ) {
11311132 pending_monitor_writes = chain_monitor. get_cm ( ) . pending_operation_count ( ) ;
@@ -1139,7 +1140,12 @@ where
11391140 CHANNEL_MANAGER_PERSISTENCE_KEY ,
11401141 channel_manager. get_cm ( ) . encode ( ) ,
11411142 )
1142- . await
1143+ . await ?;
1144+
1145+ // Flush monitor operations that were pending before we persisted. New updates
1146+ // that arrived after are left for the next iteration.
1147+ chain_monitor. get_cm ( ) . flush ( pending_monitor_writes, & logger) ;
1148+ Ok ( ( ) )
11431149 } ;
11441150 // TODO: Once our MSRV is 1.68 we should be able to drop the Box
11451151 let mut fut = Box :: pin ( fut) ;
@@ -1325,10 +1331,6 @@ where
13251331 res?;
13261332 }
13271333
1328- // Flush monitor operations that were pending before we persisted. New updates
1329- // that arrived after are left for the next iteration.
1330- chain_monitor. get_cm ( ) . flush ( pending_monitor_writes, & logger) ;
1331-
13321334 match check_and_reset_sleeper ( & mut last_onion_message_handler_call, || {
13331335 sleeper ( ONION_MESSAGE_HANDLER_TIMER )
13341336 } ) {
0 commit comments