Welcome! Log In Create A New Profile

Advanced

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

Roman Arutyunyan
June 02, 2022 09:42AM
On Mon, May 30, 2022 at 05:54:34PM +0400, Sergey Kandaurov wrote:
>
> > On 18 May 2022, at 10:57, Roman Arutyunyan <arut@nginx.com> wrote:
> >
> > # HG changeset patch
> > # User Roman Arutyunyan <arut@nginx.com>
> > # Date 1652852691 -14400
> > # Wed May 18 09:44:51 2022 +0400
> > # Branch quic
> > # Node ID 67ae4b649f2e38a44b245b7a842cf396c8250f02
> > # Parent c2f5d79cde64457f1fa7344c56a5248a677a7e46
> > QUIC: reusable and idle modes for main connection.
> >
> > The modes are controlled by application layer. For HTTP/3, they are enabled
> > when there are no active request streams.
> >
> > 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
> > @@ -414,8 +414,8 @@ ngx_quic_input_handler(ngx_event_t *rev)
> > }
> >
> > if (c->close) {
> > - qc->error_reason = "graceful shutdown";
> > - ngx_quic_close_connection(c, NGX_OK);
> > + qc->error = NGX_QUIC_ERR_NO_ERROR;
> > + ngx_quic_close_connection(c, NGX_ERROR);
> > return;
> > }
> >
> > 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
> > @@ -161,6 +161,7 @@ ngx_quic_close_streams(ngx_connection_t
> > ngx_pool_t *pool;
> > ngx_queue_t *q;
> > ngx_rbtree_t *tree;
> > + ngx_connection_t *sc;
> > ngx_rbtree_node_t *node;
> > ngx_quic_stream_t *qs;
> >
> > @@ -185,24 +186,41 @@ ngx_quic_close_streams(ngx_connection_t
> > return NGX_OK;
> > }
> >
> > -#if (NGX_DEBUG)
> > - ns = 0;
> > -#endif
> > -
> > node = ngx_rbtree_min(tree->root, tree->sentinel);
> >
> > while (node) {
> > qs = (ngx_quic_stream_t *) node;
> > node = ngx_rbtree_next(tree, node);
> > + sc = qs->connection;
> > +
> > + if (sc == NULL) {
> > + ngx_quic_close_stream(qs);
> > + continue;
> > + }
> > +
> > + if (c->close || sc->idle || sc->reusable) {
> > + sc->close = 1;
> > + sc->read->handler(sc->read);
> > + }
> > + }
> > +
> > + if (tree->root == tree->sentinel) {
> > + return NGX_OK;
> > + }
> > +
> > +#if (NGX_DEBUG)
> > + ns = 0;
> > +#endif
> > +
> > + for (node = ngx_rbtree_min(tree->root, tree->sentinel);
> > + node;
> > + node = ngx_rbtree_next(tree, node))
> > + {
> > + qs = (ngx_quic_stream_t *) node;
> >
> > qs->recv_state = NGX_QUIC_STREAM_RECV_RESET_RECVD;
> > qs->send_state = NGX_QUIC_STREAM_SEND_RESET_SENT;
> >
> > - if (qs->connection == NULL) {
> > - ngx_quic_close_stream(qs);
> > - continue;
> > - }
> > -
> > ngx_quic_set_event(qs->connection->read);
> > ngx_quic_set_event(qs->connection->write);
> >
> > @@ -587,6 +605,7 @@ ngx_quic_create_stream(ngx_connection_t
> > {
> > ngx_log_t *log;
> > ngx_pool_t *pool;
> > + ngx_uint_t reusable;
> > ngx_queue_t *q;
> > ngx_connection_t *sc;
> > ngx_quic_stream_t *qs;
> > @@ -639,7 +658,13 @@ ngx_quic_create_stream(ngx_connection_t
> > *log = *c->log;
> > pool->log = log;
> >
> > + reusable = c->reusable;
> > + ngx_reusable_connection(c, 0);
> > +
> > sc = ngx_get_connection(c->fd, log);
> > +
> > + ngx_reusable_connection(c, reusable);
> > +
>
> jftr, this pollutes debug log a bit, but generally looks ok.
>
> > if (sc == NULL) {
> > ngx_destroy_pool(pool);
> > ngx_queue_insert_tail(&qc->streams.free, &qs->queue);
> > 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
> > @@ -210,6 +210,11 @@ ngx_http_v3_init_request_stream(ngx_conn
> >
> > h3c = ngx_http_v3_get_session(c);
> >
> > + if (ngx_terminate || ngx_exiting) {
> > + h3c->goaway = 1;
> > + (void) ngx_http_v3_send_goaway(c, c->quic->id);
> > + }
> > +
>
> This results in ever increasing GOAWAY identifiers if multiple
> new client streams received after graceful shutdown initiated.
> This is forbidden per rfc9114, 5.2. Connection Shutdown.
>
> I wonder if it should move after the below condition.

We cannot move it below since we need the below condition to work in case
of (ngx_terminating || ngx_exiting) too.

I suggest that we add !h3c->goaway to the new condition.

> > if (h3c->goaway) {
> > c->close = 1;
> > ngx_http_close_connection(c);
> > @@ -258,7 +263,7 @@ ngx_http_v3_wait_request_handler(ngx_eve
> > size_t size;
> > ssize_t n;
> > ngx_buf_t *b;
> > - ngx_connection_t *c;
> > + ngx_connection_t *c, *pc;
> > ngx_pool_cleanup_t *cln;
> > ngx_http_request_t *r;
> > ngx_http_connection_t *hc;
> > @@ -385,6 +390,10 @@ ngx_http_v3_wait_request_handler(ngx_eve
> > h3c = ngx_http_v3_get_session(c);
> > h3c->nrequests++;
> >
> > + pc = c->quic->parent;
> > + pc->idle = 0;
> > + ngx_reusable_connection(pc, 0);
> > +
> > if (h3c->keepalive.timer_set) {
> > ngx_del_timer(&h3c->keepalive);
> > }
> > @@ -430,7 +439,7 @@ ngx_http_v3_cleanup_request(void *data)
> > {
> > ngx_http_request_t *r = data;
> >
> > - ngx_connection_t *c;
> > + ngx_connection_t *c, *pc;
> > ngx_http_v3_session_t *h3c;
> > ngx_http_core_loc_conf_t *clcf;
> >
> > @@ -443,6 +452,16 @@ ngx_http_v3_cleanup_request(void *data)
> > 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;
> > + }
> > +
> > + pc->idle = 1;
> > + 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);
> > }
> > diff --git a/src/http/v3/ngx_http_v3_uni.c b/src/http/v3/ngx_http_v3_uni.c
> > --- a/src/http/v3/ngx_http_v3_uni.c
> > +++ b/src/http/v3/ngx_http_v3_uni.c
> > @@ -182,6 +182,11 @@ ngx_http_v3_uni_read_handler(ngx_event_t
> >
> > ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler");
> >
> > + if (c->close) {
> > + ngx_http_v3_close_uni_stream(c);
> > + return;
> > + }
> > +
> > ngx_memzero(&b, sizeof(ngx_buf_t));
> >
> > while (rev->ready) {
> > @@ -262,6 +267,11 @@ ngx_http_v3_uni_dummy_read_handler(ngx_e
> >
> > ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy read handler");
> >
> > + if (c->close) {
> > + ngx_http_v3_close_uni_stream(c);
> > + return;
> > + }
> > +
> > if (rev->ready) {
> > if (c->recv(c, &ch, 1) != 0) {
> > ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, NULL);
> >
>
> --
> Sergey Kandaurov
>
> _______________________________________________
> nginx-devel mailing list -- nginx-devel@nginx.org
> To unsubscribe send an email to nginx-devel-leave@nginx.org
_______________________________________________
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 225 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 187 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: 221
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