Welcome! Log In Create A New Profile

Advanced

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

Roman Arutyunyan
June 23, 2022 12:00PM
# HG changeset patch
# User Roman Arutyunyan <arut@nginx.com>
# Date 1655904279 -14400
# Wed Jun 22 17:24:39 2022 +0400
# Branch quic
# Node ID 1912c09e0e4d746ec0a4c2140b6d2046b283b647
# Parent ea555f7caec372e93e1b9a11ed822002e97ed58b
QUIC: removed ngx_quic_shutdown_connection().

HTTP/3 shutdown is now controlled by HTTP/3 layer. QUIC connection is
finalized after reaching requests limit when all request streams have finished.

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
@@ -82,7 +82,6 @@ ngx_quic_connstate_dbg(ngx_connection_t
}
}

- p = ngx_slprintf(p, last, "%s", qc->shutdown ? " shutdown" : "");
p = ngx_slprintf(p, last, "%s", qc->closing ? " closing" : "");
p = ngx_slprintf(p, last, "%s", qc->draining ? " draining" : "");
p = ngx_slprintf(p, last, "%s", qc->key_phase ? " kp" : "");
@@ -425,9 +424,6 @@ ngx_quic_input_handler(ngx_event_t *rev)
if (!rev->ready) {
if (qc->closing) {
ngx_quic_close_connection(c, NGX_OK);
-
- } else if (qc->shutdown) {
- ngx_quic_shutdown_quic(c);
}

return;
@@ -635,21 +631,6 @@ ngx_quic_finalize_connection(ngx_connect
}


-void
-ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,
- const char *reason)
-{
- ngx_quic_connection_t *qc;
-
- qc = ngx_quic_get_connection(c);
- qc->shutdown = 1;
- qc->shutdown_code = err;
- qc->shutdown_reason = reason;
-
- ngx_quic_shutdown_quic(c);
-}
-
-
static void
ngx_quic_close_timer_handler(ngx_event_t *ev)
{
@@ -1438,36 +1419,3 @@ ngx_quic_push_handler(ngx_event_t *ev)

ngx_quic_connstate_dbg(c);
}
-
-
-void
-ngx_quic_shutdown_quic(ngx_connection_t *c)
-{
- ngx_rbtree_t *tree;
- ngx_rbtree_node_t *node;
- ngx_quic_stream_t *qs;
- ngx_quic_connection_t *qc;
-
- qc = ngx_quic_get_connection(c);
-
- if (qc->closing) {
- return;
- }
-
- tree = &qc->streams.tree;
-
- if (tree->root != tree->sentinel) {
- for (node = ngx_rbtree_min(tree->root, tree->sentinel);
- node;
- node = ngx_rbtree_next(tree, node))
- {
- qs = (ngx_quic_stream_t *) node;
-
- if (!qs->cancelable) {
- return;
- }
- }
- }
-
- ngx_quic_finalize_connection(c, qc->shutdown_code, qc->shutdown_reason);
-}
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
@@ -111,8 +111,6 @@ void ngx_quic_terminate_connection(ngx_c
const char *reason);
void ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err,
const char *reason);
-void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,
- const char *reason);
ngx_int_t ngx_quic_reset_stream(ngx_connection_t *c, ngx_uint_t err);
ngx_int_t ngx_quic_shutdown_stream(ngx_connection_t *c, int how);
ngx_int_t ngx_quic_handle_read_event(ngx_event_t *rev, ngx_uint_t flags);
diff --git a/src/event/quic/ngx_event_quic_connection.h b/src/event/quic/ngx_event_quic_connection.h
--- a/src/event/quic/ngx_event_quic_connection.h
+++ b/src/event/quic/ngx_event_quic_connection.h
@@ -246,13 +246,9 @@ struct ngx_quic_connection_s {
ngx_uint_t error_ftype;
const char *error_reason;

- ngx_uint_t shutdown_code;
- const char *shutdown_reason;
-
unsigned error_app:1;
unsigned send_timer_set:1;
unsigned closing:1;
- unsigned shutdown:1;
unsigned draining:1;
unsigned key_phase:1;
unsigned validated:1;
@@ -265,7 +261,6 @@ ngx_int_t ngx_quic_apply_transport_param
void ngx_quic_discard_ctx(ngx_connection_t *c,
enum ssl_encryption_level_t level);
void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc);
-void ngx_quic_shutdown_quic(ngx_connection_t *c);

#if (NGX_DEBUG)
void ngx_quic_connstate_dbg(ngx_connection_t *c);
diff --git a/src/event/quic/ngx_event_quic_streams.c b/src/event/quic/ngx_event_quic_streams.c
--- a/src/event/quic/ngx_event_quic_streams.c
+++ b/src/event/quic/ngx_event_quic_streams.c
@@ -385,7 +385,7 @@ ngx_quic_get_stream(ngx_connection_t *c,
return qs;
}

- if (qc->shutdown || qc->closing) {
+ if (qc->closing) {
return NGX_QUIC_STREAM_GONE;
}

@@ -1081,10 +1081,6 @@ ngx_quic_close_stream(ngx_quic_stream_t
ngx_quic_queue_frame(qc, frame);
}

- if (qc->shutdown) {
- ngx_post_event(pc->read, &ngx_posted_events);
- }
-
return NGX_OK;
}

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
@@ -95,10 +95,6 @@
ngx_quic_finalize_connection((c)->quic ? (c)->quic->parent : (c), \
code, reason)

-#define ngx_http_v3_shutdown_connection(c, code, reason) \
- ngx_quic_shutdown_connection((c)->quic ? (c)->quic->parent : (c), \
- code, reason)
-

typedef struct {
size_t max_table_capacity;
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
@@ -14,6 +14,7 @@
static void ngx_http_v3_init_hq_stream(ngx_connection_t *c);
#endif
static void ngx_http_v3_init_request_stream(ngx_connection_t *c);
+static void ngx_http_v3_cleanup_connection(void *data);
static void ngx_http_v3_wait_request_handler(ngx_event_t *rev);
static void ngx_http_v3_cleanup_request(void *data);
static void ngx_http_v3_process_request(ngx_event_t *rev);
@@ -184,6 +185,8 @@ ngx_http_v3_init_request_stream(ngx_conn
{
uint64_t n;
ngx_event_t *rev;
+ ngx_connection_t *pc;
+ ngx_pool_cleanup_t *cln;
ngx_http_connection_t *hc;
ngx_http_v3_session_t *h3c;
ngx_http_core_loc_conf_t *clcf;
@@ -221,9 +224,10 @@ ngx_http_v3_init_request_stream(ngx_conn
return;
}

+ pc = c->quic->parent;
+
if (n + 1 == clcf->keepalive_requests
- || ngx_current_msec - c->quic->parent->start_time
- > clcf->keepalive_time)
+ || ngx_current_msec - pc->start_time > clcf->keepalive_time)
{
h3c->goaway = 1;

@@ -231,9 +235,25 @@ ngx_http_v3_init_request_stream(ngx_conn
ngx_http_close_connection(c);
return;
}
+ }

- ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "reached maximum number of requests");
+ cln = ngx_pool_cleanup_add(c->pool, 0);
+ if (cln == NULL) {
+ ngx_quic_finalize_connection(pc, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
+ "internal error");
+ ngx_http_close_connection(c);
+ return;
+ }
+
+ cln->handler = ngx_http_v3_cleanup_connection;
+ cln->data = c;
+
+ if (h3c->nrequests++ == 0) {
+ ngx_reusable_connection(pc, 0);
+ }
+
+ if (h3c->keepalive.timer_set) {
+ ngx_del_timer(&h3c->keepalive);
}

rev = c->read;
@@ -258,16 +278,43 @@ ngx_http_v3_init_request_stream(ngx_conn


static void
+ngx_http_v3_cleanup_connection(void *data)
+{
+ ngx_connection_t *c = data;
+
+ ngx_connection_t *pc;
+ ngx_http_v3_session_t *h3c;
+ ngx_http_core_loc_conf_t *clcf;
+
+ h3c = ngx_http_v3_get_session(c);
+
+ if (--h3c->nrequests == 0) {
+ pc = c->quic->parent;
+
+ if (h3c->goaway) {
+ ngx_quic_finalize_connection(pc, NGX_HTTP_V3_ERR_NO_ERROR,
+ "connection shutdown");
+ return;
+ }
+
+ ngx_reusable_connection(pc, 1);
+
+ clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
+ ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
+ }
+}
+
+
+static void
ngx_http_v3_wait_request_handler(ngx_event_t *rev)
{
size_t size;
ssize_t n;
ngx_buf_t *b;
- ngx_connection_t *c, *pc;
+ ngx_connection_t *c;
ngx_pool_cleanup_t *cln;
ngx_http_request_t *r;
ngx_http_connection_t *hc;
- ngx_http_v3_session_t *h3c;
ngx_http_core_srv_conf_t *cscf;

c = rev->data;
@@ -387,16 +434,6 @@ ngx_http_v3_wait_request_handler(ngx_eve
cln->handler = ngx_http_v3_cleanup_request;
cln->data = r;

- h3c = ngx_http_v3_get_session(c);
- h3c->nrequests++;
-
- pc = c->quic->parent;
- ngx_reusable_connection(pc, 0);
-
- if (h3c->keepalive.timer_set) {
- ngx_del_timer(&h3c->keepalive);
- }
-
rev->handler = ngx_http_v3_process_request;
ngx_http_v3_process_request(rev);
}
@@ -438,30 +475,8 @@ ngx_http_v3_cleanup_request(void *data)
{
ngx_http_request_t *r = data;

- ngx_connection_t *c, *pc;
- ngx_http_v3_session_t *h3c;
- ngx_http_core_loc_conf_t *clcf;
-
- c = r->connection;
-
if (!r->response_sent) {
- c->error = 1;
- }
-
- h3c = ngx_http_v3_get_session(c);
-
- if (--h3c->nrequests == 0) {
- pc = c->quic->parent;
-
- if (ngx_terminate || ngx_exiting) {
- ngx_quic_finalize_connection(pc, NGX_HTTP_V3_ERR_NO_ERROR, NULL);
- return;
- }
-
- ngx_reusable_connection(pc, 1);
-
- clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
- ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
+ r->connection->error = 1;
}
}


_______________________________________________
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 1402 May 18, 2022 03:00AM

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

Roman Arutyunyan 203 May 18, 2022 03:02AM

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

Sergey Kandaurov 260 May 30, 2022 09:56AM

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

Roman Arutyunyan 194 June 02, 2022 09:42AM

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

Roman Arutyunyan 207 May 18, 2022 03:04AM

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

Sergey Kandaurov 208 May 30, 2022 05:56PM

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

Roman Arutyunyan 187 June 02, 2022 09:46AM

[PATCH 0 of 3] QUIC connection reuse

Roman Arutyunyan 195 June 02, 2022 09:54AM

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

Roman Arutyunyan 201 June 02, 2022 09:54AM

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

Sergey Kandaurov 192 June 06, 2022 06:44AM

[PATCH 0 of 8] QUIC connection reuse

Roman Arutyunyan 171 June 23, 2022 12:00PM

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

Roman Arutyunyan 201 June 23, 2022 12:00PM

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

Roman Arutyunyan 318 June 23, 2022 12:00PM

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

Sergey Kandaurov 203 August 02, 2022 09:50AM

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

Roman Arutyunyan 143 August 23, 2022 08:22AM

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

Roman Arutyunyan 224 June 23, 2022 12:00PM

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

Sergey Kandaurov 177 August 02, 2022 11:46AM

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

Roman Arutyunyan 144 August 23, 2022 08:30AM

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

Roman Arutyunyan 175 June 23, 2022 12:00PM

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

Roman Arutyunyan 174 June 23, 2022 12:00PM

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

Roman Arutyunyan 167 June 23, 2022 12:00PM

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

Roman Arutyunyan 163 June 23, 2022 12:00PM

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

Roman Arutyunyan 186 June 23, 2022 12:00PM

[PATCH 0 of 9] QUIC connection reuse

Roman Arutyunyan 153 August 23, 2022 08:52AM

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

Roman Arutyunyan 171 August 23, 2022 08:52AM

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

Roman Arutyunyan 139 August 23, 2022 08:52AM

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

Roman Arutyunyan 139 August 23, 2022 08:52AM

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

Roman Arutyunyan 143 August 23, 2022 08:52AM

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

Roman Arutyunyan 172 August 23, 2022 08:52AM

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

Roman Arutyunyan 161 August 23, 2022 08:54AM

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

Roman Arutyunyan 137 August 23, 2022 08:54AM

[PATCH 00 of 10] QUIC connection reuse

Roman Arutyunyan 139 September 08, 2022 05:08AM

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

Roman Arutyunyan 130 September 08, 2022 05:08AM

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

Roman Arutyunyan 143 September 08, 2022 05:10AM

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

Roman Arutyunyan 138 September 08, 2022 05:10AM

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

Roman Arutyunyan 134 September 08, 2022 05:10AM

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

Sergey Kandaurov 125 October 20, 2022 07:36AM

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

Roman Arutyunyan 150 October 20, 2022 09:56AM

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

Roman Arutyunyan 147 September 08, 2022 05:10AM

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

Sergey Kandaurov 110 November 28, 2022 11:12AM

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

Roman Arutyunyan 152 September 08, 2022 05:10AM

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

Sergey Kandaurov 158 October 20, 2022 07:52AM

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

Roman Arutyunyan 143 October 20, 2022 10:26AM

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

Roman Arutyunyan 186 November 24, 2022 10:18AM

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

Sergey Kandaurov 119 November 28, 2022 12:42PM

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

Roman Arutyunyan 112 November 29, 2022 09:02AM

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

Roman Arutyunyan 130 November 30, 2022 05:14AM

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

Roman Arutyunyan 141 September 08, 2022 05:10AM

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

Roman Arutyunyan 142 September 08, 2022 05:10AM

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

Sergey Kandaurov 129 October 20, 2022 07:54AM

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

Roman Arutyunyan 160 October 20, 2022 10:34AM

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

Roman Arutyunyan 195 October 25, 2022 05:12AM

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

Roman Arutyunyan 213 September 08, 2022 05:10AM



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

Online Users

Guests: 164
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready