@@ -834,6 +834,30 @@ fd_quic_log_full_hdr( fd_quic_conn_t const * conn,
834
834
return hdr ;
835
835
}
836
836
837
+ static inline void
838
+ fd_quic_set_conn_state ( fd_quic_conn_t * conn ,
839
+ uint new_state ) {
840
+
841
+ uint old_state = conn -> state ;
842
+
843
+ FD_COMPILER_MFENCE ();
844
+
845
+ int was_timed_out = !!(old_state == FD_QUIC_CONN_STATE_TIMED_OUT );
846
+ int freeing = was_timed_out & !!(new_state == FD_QUIC_CONN_STATE_INVALID );
847
+ int reviving = was_timed_out & !freeing & !(new_state == FD_QUIC_CONN_STATE_TIMED_OUT );
848
+
849
+ fd_quic_metrics_t * metrics = & conn -> quic -> metrics ;
850
+ metrics -> conn_timeout_freed_cnt += (ulong )freeing ;
851
+ metrics -> conn_timeout_revived_cnt += (ulong )reviving ;
852
+
853
+ metrics -> conn_state_cnt [ old_state ]-- ;
854
+ metrics -> conn_state_cnt [ new_state ]++ ;
855
+
856
+ conn -> state = new_state ;
857
+
858
+ FD_COMPILER_MFENCE ();
859
+ }
860
+
837
861
/* fd_quic_conn_error sets the connection state to aborted. This does
838
862
not destroy the connection object. Rather, it will eventually cause
839
863
the connection to be freed during a later fd_quic_service call.
@@ -2277,6 +2301,11 @@ fd_quic_handle_v1_one_rtt( fd_quic_t * quic,
2277
2301
/* update expected packet number */
2278
2302
conn -> exp_pkt_number [2 ] = fd_ulong_max ( conn -> exp_pkt_number [2 ], pkt_number + 1UL );
2279
2303
2304
+ /* Revive conn if it was timed out */
2305
+ if ( FD_UNLIKELY ( conn -> state == FD_QUIC_CONN_STATE_TIMED_OUT ) ) {
2306
+ fd_quic_set_conn_state ( conn , FD_QUIC_CONN_STATE_ACTIVE );
2307
+ }
2308
+
2280
2309
return tot_sz ;
2281
2310
}
2282
2311
@@ -2381,13 +2410,6 @@ fd_quic_process_quic_packet_v1( fd_quic_t * quic,
2381
2410
return FD_QUIC_PARSE_FAIL ;
2382
2411
}
2383
2412
2384
- /* If connection is timed out, revive it if packet successfully handled. */
2385
- if ( FD_UNLIKELY ( conn && conn -> state == FD_QUIC_CONN_STATE_TIMED_OUT ) ) {
2386
- quic -> metrics .conn_timeout_revived_cnt ++ ;
2387
- fd_quic_set_conn_state ( conn , FD_QUIC_CONN_STATE_ACTIVE );
2388
- fd_quic_svc_schedule ( state , conn , FD_QUIC_SVC_WAIT );
2389
- }
2390
-
2391
2413
cur_ptr += rc ;
2392
2414
2393
2415
/* if we get here we parsed all the frames, so ack the packet */
@@ -2868,6 +2890,7 @@ fd_quic_tls_cb_handshake_complete( fd_quic_tls_hs_t * hs,
2868
2890
return ;
2869
2891
2870
2892
case FD_QUIC_CONN_STATE_HANDSHAKE :
2893
+ case FD_QUIC_CONN_STATE_TIMED_OUT :
2871
2894
if ( FD_UNLIKELY ( !conn -> transport_params_set ) ) { /* unreachable */
2872
2895
FD_LOG_WARNING (( "Handshake marked as completed but transport params are not set. This is a bug!" ));
2873
2896
fd_quic_conn_error ( conn , FD_QUIC_CONN_REASON_INTERNAL_ERROR , __LINE__ );
@@ -4151,7 +4174,6 @@ fd_quic_free_timed_out( fd_quic_t * quic ) {
4151
4174
fd_quic_conn_t * conn = fd_quic_conn_at_idx ( state , queue -> head );
4152
4175
fd_quic_svc_pop_head ( state , queue , conn );
4153
4176
4154
- quic -> metrics .conn_timeout_freed_cnt ++ ;
4155
4177
fd_quic_conn_free ( quic , conn );
4156
4178
}
4157
4179
0 commit comments