Skip to content

Commit 6437b3a

Browse files
quic: keep alive in config
1 parent ba8db0c commit 6437b3a

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

src/waltz/quic/fd_quic.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@
3939
#define MAP_QUERY_OPT 1
4040
#include "../../util/tmpl/fd_map_dynamic.c"
4141

42-
/* FD_QUIC_KEEP_ALIVE
43-
*
44-
* This compile time option specifies whether the server should use
45-
* QUIC PING frames to keep connections alive
46-
*
47-
* Set to 1 to keep connections alive
48-
* Set to 0 to allow connections to close on idle */
49-
# define FD_QUIC_KEEP_ALIVE 0
5042

5143
/* FD_QUIC_MAX_STREAMS_ALWAYS_UNLESS_ACKED */
5244
/* Defines whether a MAX_STREAMS frame is sent even if it was just */
@@ -2832,23 +2824,21 @@ fd_quic_svc_poll( fd_quic_t * quic,
28322824
return 1;
28332825
}
28342826

2835-
//FD_DEBUG( FD_LOG_DEBUG(( "svc_poll conn=%p svc_type=%u", (void *)conn, conn->svc_type )); )
2836-
28372827
if( FD_UNLIKELY( now >= conn->last_activity + ( conn->idle_timeout / 2 ) ) ) {
28382828
if( FD_UNLIKELY( now >= conn->last_activity + conn->idle_timeout ) ) {
28392829
if( FD_LIKELY( conn->state != FD_QUIC_CONN_STATE_DEAD ) ) {
28402830
/* rfc9000 10.1 Idle Timeout
28412831
"... the connection is silently closed and its state is discarded
28422832
when it remains idle for longer than the minimum of the
28432833
max_idle_timeout value advertised by both endpoints." */
2844-
FD_DEBUG( FD_LOG_WARNING(( "%s conn %p conn_idx: %u closing due to idle timeout (%g ms)",
2834+
FD_DEBUG( FD_LOG_WARNING(("%s conn %p conn_idx: %u closing due to idle timeout (%g ms)",
28452835
conn->server?"SERVER":"CLIENT",
28462836
(void *)conn, conn->conn_idx, (double)conn->idle_timeout / 1e6 )); )
28472837

28482838
fd_quic_set_conn_state( conn, FD_QUIC_CONN_STATE_DEAD );
28492839
quic->metrics.conn_timeout_cnt++;
28502840
}
2851-
} else if( FD_QUIC_KEEP_ALIVE ) {
2841+
} else if( quic->config.keep_alive ) {
28522842
/* send PING */
28532843
if( !( conn->flags & FD_QUIC_CONN_FLAGS_PING ) ) {
28542844
conn->flags |= FD_QUIC_CONN_FLAGS_PING;
@@ -2876,7 +2866,8 @@ fd_quic_svc_poll( fd_quic_t * quic,
28762866
fd_quic_conn_free( quic, conn );
28772867
break;
28782868
default:
2879-
fd_quic_svc_prep_schedule( conn, state->now + quic->config.idle_timeout );
2869+
/* prep idle timeout or keep alive at idle timeout/2 */
2870+
fd_quic_svc_prep_schedule( conn, state->now + (conn->idle_timeout>>(quic->config.keep_alive)) );
28802871
fd_quic_svc_schedule( state->svc_timers, conn );
28812872
break;
28822873
}
@@ -4292,8 +4283,9 @@ fd_quic_conn_create( fd_quic_t * quic,
42924283

42934284
fd_quic_svc_timers_init_conn( conn );
42944285

4295-
/* prep idle timeout */
4296-
fd_quic_svc_prep_schedule( conn, state->now+quic->config.idle_timeout );
4286+
/* prep idle timeout or keep alive at idle timeout/2 */
4287+
ulong delay = quic->config.idle_timeout>>(quic->config.keep_alive);
4288+
fd_quic_svc_prep_schedule( conn, state->now+delay );
42974289

42984290
/* return connection */
42994291
return conn;

src/waltz/quic/fd_quic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ struct __attribute__((aligned(16UL))) fd_quic_config {
169169
ulong idle_timeout;
170170
# define FD_QUIC_DEFAULT_IDLE_TIMEOUT (ulong)(1e9) /* 1s */
171171

172+
/* keep_alive
173+
* whether the fd_quic should use QUIC PING frames to keep connections alive
174+
* Set to 1 to keep connections alive
175+
* Set to 0 to allow connections to close on idle
176+
* default is 0 */
177+
int keep_alive;
178+
172179
/* ack_delay: median delay on outgoing ACKs. Greater delays allow
173180
fd_quic to coalesce packet ACKs. */
174181
ulong ack_delay;

src/waltz/quic/tests/test_quic_hs.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,31 @@ main( int argc, char ** argv ) {
199199
FD_LOG_INFO(( "fd_quic_stream_send returned %d", rc ));
200200
}
201201

202+
/* testing keep_alive */
203+
ulong const idle_timeout = fd_ulong_min(
204+
client_quic->config.idle_timeout,
205+
server_quic->config.idle_timeout
206+
);
207+
ulong const timestep = idle_timeout>>3;
208+
209+
for( int keep_alive=1; keep_alive>=0; --keep_alive ) {
210+
client_quic->config.keep_alive = keep_alive;
211+
for( int i=0; i<10; ++i ) {
212+
now+=timestep;
213+
fd_quic_service( client_quic );
214+
fd_quic_service( server_quic );
215+
}
216+
if( keep_alive ) {
217+
FD_TEST( client_conn->state == FD_QUIC_CONN_STATE_ACTIVE );
218+
} else {
219+
FD_TEST( client_conn->state == FD_QUIC_CONN_STATE_DEAD ||
220+
client_conn->state == FD_QUIC_CONN_STATE_INVALID );
221+
}
222+
}
223+
224+
FD_LOG_NOTICE(( "Validated idle_timeout and keep_alive" ));
225+
226+
202227
FD_LOG_NOTICE(( "Closing connections" ));
203228

204229
fd_quic_state_validate( server_quic );

0 commit comments

Comments
 (0)