@@ -166,6 +166,49 @@ mod moved_tests {
166166 event_task. await . expect ( "event task should complete" ) ;
167167 }
168168
169+ #[ tokio:: test]
170+ async fn transport_close_during_preflight_never_emits_connection_closed ( ) {
171+ let ctx = ActorContext :: new_with_kv (
172+ "actor-preflight-transport-close" ,
173+ "actor" ,
174+ Vec :: new ( ) ,
175+ "local" ,
176+ Kv :: new_in_memory ( ) ,
177+ ) ;
178+ ctx. configure_connection_runtime ( crate :: actor:: config:: ActorConfig :: default ( ) ) ;
179+ let ( events_tx, mut events_rx) = mpsc:: unbounded_channel ( ) ;
180+ ctx. configure_actor_events ( Some ( events_tx) ) ;
181+ let closed_conn_id = Arc :: new ( Mutex :: new ( None :: < String > ) ) ;
182+
183+ let event_closed_conn_id = closed_conn_id. clone ( ) ;
184+ let event_task = tokio:: spawn ( async move {
185+ match events_rx. recv ( ) . await . expect ( "preflight event" ) {
186+ ActorEvent :: ConnectionPreflight { conn, reply, .. } => {
187+ conn. disconnect ( Some ( "transport closed" ) )
188+ . await
189+ . expect ( "pending connection transport close should succeed" ) ;
190+ reply. send ( Err ( anyhow:: anyhow!( "reject after transport close" ) ) ) ;
191+ }
192+ other => panic ! ( "unexpected event: {other:?}" ) ,
193+ }
194+
195+ if let Ok ( Some ( ActorEvent :: ConnectionClosed { conn } ) ) =
196+ tokio:: time:: timeout ( Duration :: from_millis ( 20 ) , events_rx. recv ( ) ) . await
197+ {
198+ * event_closed_conn_id. lock ( ) = Some ( conn. id ( ) . to_owned ( ) ) ;
199+ }
200+ } ) ;
201+
202+ let error = ctx
203+ . connect_with_state ( vec ! [ 1 ] , false , None , None , async { Ok ( vec ! [ 2 ] ) } )
204+ . await
205+ . expect_err ( "connection should fail" ) ;
206+
207+ assert ! ( format!( "{error:#}" ) . contains( "reject after transport close" ) ) ;
208+ assert_eq ! ( * closed_conn_id. lock( ) , None ) ;
209+ event_task. await . expect ( "event task should complete" ) ;
210+ }
211+
169212 #[ test]
170213 fn persisted_connection_uses_ts_v4_fixed_id_wire_format ( ) {
171214 let persisted = PersistedConnection {
0 commit comments