Welcome! Log In Create A New Profile

Advanced

[PATCH 08 of 10] QUIC: idle mode for main connection

Roman Arutyunyan
September 08, 2022 05:10AM
# HG changeset patch
# User Roman Arutyunyan <arut@nginx.com>
# Date 1662627133 -14400
# Thu Sep 08 12:52:13 2022 +0400
# Branch quic
# Node ID e0634a484d9a2d82d43f565d64a0a22e989ac1cb
# Parent 1dd6fabfdcb5b52af495f9d8fc00f64ae36a537c
QUIC: idle mode for main connection.

Now main QUIC connection for HTTP/3 always has c->idle flag set. This allows
the connection to receive worker shutdown notification. It is passed to
application level via a new conf->shutdown() callback.

The HTTP/3 shutdown callback sends GOAWAY to client and gracefully shuts down
the QUIC connection.

diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c
--- a/src/event/quic/ngx_event_quic.c
+++ b/src/event/quic/ngx_event_quic.c
@@ -341,6 +341,7 @@ ngx_quic_new_connection(ngx_connection_t
return NULL;
}

+ c->idle = 1;
ngx_reusable_connection(c, 1);

ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
@@ -420,9 +421,9 @@ ngx_quic_input_handler(ngx_event_t *rev)
}

if (c->close) {
- qc->error = NGX_QUIC_ERR_NO_ERROR;
- qc->error_reason = "graceful shutdown";
- ngx_quic_close_connection(c, NGX_ERROR);
+ if (qc->conf->shutdown) {
+ qc->conf->shutdown(c);
+ }
return;
}

diff --git a/src/event/quic/ngx_event_quic.h b/src/event/quic/ngx_event_quic.h
--- a/src/event/quic/ngx_event_quic.h
+++ b/src/event/quic/ngx_event_quic.h
@@ -28,6 +28,9 @@
#define NGX_QUIC_STREAM_UNIDIRECTIONAL 0x02


+typedef void (*ngx_quic_shutdown_pt)(ngx_connection_t *c);
+
+
typedef enum {
NGX_QUIC_STREAM_SEND_READY = 0,
NGX_QUIC_STREAM_SEND_SEND,
@@ -74,6 +77,8 @@ typedef struct {
ngx_int_t stream_reject_code_uni;
ngx_int_t stream_reject_code_bidi;

+ ngx_quic_shutdown_pt shutdown;
+
u_char av_token_key[NGX_QUIC_AV_KEY_LEN];
u_char sr_token_key[NGX_QUIC_SR_KEY_LEN];
} ngx_quic_conf_t;
diff --git a/src/http/v3/ngx_http_v3.h b/src/http/v3/ngx_http_v3.h
--- a/src/http/v3/ngx_http_v3.h
+++ b/src/http/v3/ngx_http_v3.h
@@ -141,6 +141,7 @@ struct ngx_http_v3_session_s {
uint64_t next_push_id;
uint64_t max_push_id;
uint64_t goaway_push_id;
+ uint64_t next_request_id;

off_t total_bytes;
off_t payload_bytes;
@@ -158,6 +159,7 @@ void ngx_http_v3_init(ngx_connection_t *
void ngx_http_v3_reset_connection(ngx_connection_t *c);
ngx_int_t ngx_http_v3_init_session(ngx_connection_t *c);
ngx_int_t ngx_http_v3_check_flood(ngx_connection_t *c);
+void ngx_http_v3_shutdown(ngx_connection_t *c);

ngx_int_t ngx_http_v3_read_request_body(ngx_http_request_t *r);
ngx_int_t ngx_http_v3_read_unbuffered_request_body(ngx_http_request_t *r);
diff --git a/src/http/v3/ngx_http_v3_module.c b/src/http/v3/ngx_http_v3_module.c
--- a/src/http/v3/ngx_http_v3_module.c
+++ b/src/http/v3/ngx_http_v3_module.c
@@ -249,6 +249,8 @@ ngx_http_v3_create_srv_conf(ngx_conf_t *
h3scf->quic.stream_reject_code_bidi = NGX_HTTP_V3_ERR_REQUEST_REJECTED;
h3scf->quic.active_connection_id_limit = NGX_CONF_UNSET_UINT;

+ h3scf->quic.shutdown = ngx_http_v3_shutdown;
+
return h3scf;
}

diff --git a/src/http/v3/ngx_http_v3_request.c b/src/http/v3/ngx_http_v3_request.c
--- a/src/http/v3/ngx_http_v3_request.c
+++ b/src/http/v3/ngx_http_v3_request.c
@@ -97,6 +97,37 @@ ngx_http_v3_init(ngx_connection_t *c)
}


+void
+ngx_http_v3_shutdown(ngx_connection_t *c)
+{
+ ngx_http_v3_session_t *h3c;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 shutdown");
+
+ h3c = ngx_http_v3_get_session(c);
+
+ if (h3c == NULL) {
+ ngx_quic_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
+ "connection shutdown");
+ return;
+ }
+
+ if (!h3c->goaway) {
+ h3c->goaway = 1;
+
+#if (NGX_HTTP_V3_HQ)
+ if (!h3c->hq)
+#endif
+ {
+ (void) ngx_http_v3_send_goaway(c, h3c->next_request_id);
+ }
+
+ ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
+ "connection shutdown");
+ }
+}
+
+
static void
ngx_http_v3_init_request_stream(ngx_connection_t *c)
{
@@ -137,6 +168,8 @@ ngx_http_v3_init_request_stream(ngx_conn

pc = c->quic->parent;

+ h3c->next_request_id = c->quic->id + 0x04;
+
if (n + 1 == clcf->keepalive_requests
|| ngx_current_msec - pc->start_time > clcf->keepalive_time)
{
@@ -146,7 +179,7 @@ ngx_http_v3_init_request_stream(ngx_conn
if (!h3c->hq)
#endif
{
- if (ngx_http_v3_send_goaway(c, (n + 1) << 2) != NGX_OK) {
+ if (ngx_http_v3_send_goaway(c, h3c->next_request_id) != NGX_OK) {
ngx_http_close_connection(c);
return;
}

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[PATCH 0 of 2] QUIC connection reuse

Roman Arutyunyan 747 May 18, 2022 03:00AM

[PATCH 1 of 2] QUIC: reusable and idle modes for main connection

Roman Arutyunyan 75 May 18, 2022 03:02AM

Re: [PATCH 1 of 2] QUIC: reusable and idle modes for main connection

Sergey Kandaurov 103 May 30, 2022 09:56AM

Re: [PATCH 1 of 2] QUIC: reusable and idle modes for main connection

Roman Arutyunyan 72 June 02, 2022 09:42AM

[PATCH 2 of 2] QUIC: init_streams() callback

Roman Arutyunyan 89 May 18, 2022 03:04AM

Re: [PATCH 2 of 2] QUIC: init_streams() callback

Sergey Kandaurov 102 May 30, 2022 05:56PM

Re: [PATCH 2 of 2] QUIC: init_streams() callback

Roman Arutyunyan 73 June 02, 2022 09:46AM

[PATCH 0 of 3] QUIC connection reuse

Roman Arutyunyan 79 June 02, 2022 09:54AM

[PATCH 2 of 3] QUIC: relocated early streams initialization

Roman Arutyunyan 68 June 02, 2022 09:54AM

Re: [PATCH 2 of 3] QUIC: relocated early streams initialization

Sergey Kandaurov 64 June 06, 2022 06:44AM

[PATCH 0 of 8] QUIC connection reuse

Roman Arutyunyan 56 June 23, 2022 12:00PM

[PATCH 2 of 8] QUIC: ngx_quic_terminate_connection() function

Roman Arutyunyan 64 June 23, 2022 12:00PM

[PATCH 1 of 8] QUIC: treat qc->error == -1 as a missing error

Roman Arutyunyan 86 June 23, 2022 12:00PM

Re: [PATCH 1 of 8] QUIC: treat qc->error == -1 as a missing error

Sergey Kandaurov 86 August 02, 2022 09:50AM

Re: [PATCH 1 of 8] QUIC: treat qc->error == -1 as a missing error

Roman Arutyunyan 31 August 23, 2022 08:22AM

[PATCH 4 of 8] QUIC: removed ngx_quic_shutdown_connection()

Roman Arutyunyan 62 June 23, 2022 12:00PM

Re: [PATCH 4 of 8] QUIC: removed ngx_quic_shutdown_connection()

Sergey Kandaurov 60 August 02, 2022 11:46AM

Re: [PATCH 4 of 8] QUIC: removed ngx_quic_shutdown_connection()

Roman Arutyunyan 32 August 23, 2022 08:30AM

[PATCH 5 of 8] HTTP/3: keepalive timer for hq mode

Roman Arutyunyan 60 June 23, 2022 12:00PM

[PATCH 8 of 8] QUIC: application init() callback

Roman Arutyunyan 68 June 23, 2022 12:00PM

[PATCH 3 of 8] QUIC: reusable mode for main connection

Roman Arutyunyan 56 June 23, 2022 12:00PM

[PATCH 7 of 8] HTTP/3: renamed functions

Roman Arutyunyan 53 June 23, 2022 12:00PM

[PATCH 6 of 8] QUIC: idle mode for main connection

Roman Arutyunyan 78 June 23, 2022 12:00PM

[PATCH 0 of 9] QUIC connection reuse

Roman Arutyunyan 38 August 23, 2022 08:52AM

[PATCH 5 of 9] QUIC: do not send MAX_STREAMS in shutdown state

Roman Arutyunyan 51 August 23, 2022 08:52AM

[PATCH 4 of 9] QUIC: defer stream removal until all its data is acked

Roman Arutyunyan 33 August 23, 2022 08:52AM

[PATCH 1 of 9] QUIC: treat qc->error == -1 as a missing error

Roman Arutyunyan 32 August 23, 2022 08:52AM

[PATCH 7 of 9] QUIC: idle mode for main connection

Roman Arutyunyan 32 August 23, 2022 08:52AM

[PATCH 8 of 9] HTTP/3: renamed functions

Roman Arutyunyan 46 August 23, 2022 08:52AM

[PATCH 9 of 9] QUIC: application init() callback

Roman Arutyunyan 41 August 23, 2022 08:54AM

[PATCH 6 of 9] HTTP/3: unified hq code with HTTP/3 code

Roman Arutyunyan 32 August 23, 2022 08:54AM

[PATCH 00 of 10] QUIC connection reuse

Roman Arutyunyan 26 September 08, 2022 05:08AM

[PATCH 06 of 10] QUIC: do not send MAX_STREAMS in shutdown state

Roman Arutyunyan 21 September 08, 2022 05:08AM

[PATCH 03 of 10] QUIC: post close event for connection close

Roman Arutyunyan 28 September 08, 2022 05:10AM

[PATCH 02 of 10] QUIC: made ngx_quic_finalize_connecion() more graceful

Roman Arutyunyan 24 September 08, 2022 05:10AM

[PATCH 07 of 10] HTTP/3: unified hq code with regular HTTP/3 code

Roman Arutyunyan 26 September 08, 2022 05:10AM

[PATCH 04 of 10] QUIC: reusable mode for main connection

Roman Arutyunyan 30 September 08, 2022 05:10AM

[PATCH 08 of 10] QUIC: idle mode for main connection

Roman Arutyunyan 39 September 08, 2022 05:10AM

[PATCH 05 of 10] QUIC: defer stream removal until all its data is acked

Roman Arutyunyan 31 September 08, 2022 05:10AM

[PATCH 10 of 10] QUIC: application init() callback

Roman Arutyunyan 31 September 08, 2022 05:10AM

[PATCH 09 of 10] HTTP/3: renamed functions

Roman Arutyunyan 33 September 08, 2022 05:10AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready