From f9781a4b7322b88dcbfa75806c9bde90641ae70f Mon Sep 17 00:00:00 2001 From: Hakase Date: Wed, 11 Jan 2023 18:21:49 +0900 Subject: [PATCH] Latest update - 9010 --- src/event/ngx_event.c | 4 +- src/event/quic/ngx_event_quic.h | 2 - src/event/quic/ngx_event_quic_streams.c | 50 ++++++++++--------------- src/http/v3/ngx_http_v3_request.c | 13 ++++--- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index 5a75597..ef525d9 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -274,7 +274,7 @@ ngx_handle_read_event(ngx_event_t *rev, ngx_uint_t flags) c = rev->data; if (c->quic) { - return ngx_quic_handle_read_event(rev, flags); + return NGX_OK; } #endif @@ -353,7 +353,7 @@ ngx_handle_write_event(ngx_event_t *wev, size_t lowat) #if (NGX_QUIC) if (c->quic) { - return ngx_quic_handle_write_event(wev, lowat); + return NGX_OK; } #endif diff --git a/src/event/quic/ngx_event_quic.h b/src/event/quic/ngx_event_quic.h index d13adbd..56713ec 100644 --- a/src/event/quic/ngx_event_quic.h +++ b/src/event/quic/ngx_event_quic.h @@ -123,8 +123,6 @@ void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err, 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); void ngx_quic_cancelable_stream(ngx_connection_t *c); -ngx_int_t ngx_quic_handle_read_event(ngx_event_t *rev, ngx_uint_t flags); -ngx_int_t ngx_quic_handle_write_event(ngx_event_t *wev, size_t lowat); ngx_int_t ngx_quic_get_packet_dcid(ngx_log_t *log, u_char *data, size_t len, ngx_str_t *dcid); ngx_int_t ngx_quic_derive_key(ngx_log_t *log, const char *label, diff --git a/src/event/quic/ngx_event_quic_streams.c b/src/event/quic/ngx_event_quic_streams.c index 2b613ac..87b6caf 100644 --- a/src/event/quic/ngx_event_quic_streams.c +++ b/src/event/quic/ngx_event_quic_streams.c @@ -203,6 +203,9 @@ ngx_quic_close_streams(ngx_connection_t *c, ngx_quic_connection_t *qc) continue; } + sc->read->error = 1; + sc->write->error = 1; + ngx_quic_set_event(sc->read); ngx_quic_set_event(sc->write); @@ -245,6 +248,10 @@ ngx_quic_do_reset_stream(ngx_quic_stream_t *qs, ngx_uint_t err) qs->send_state = NGX_QUIC_STREAM_SEND_RESET_SENT; qs->send_final_size = qs->send_offset; + if (qs->connection) { + qs->connection->write->error = 1; + } + pc = qs->parent; qc = ngx_quic_get_connection(pc); @@ -682,6 +689,7 @@ ngx_quic_create_stream(ngx_connection_t *c, uint64_t id) sc->local_sockaddr = c->local_sockaddr; sc->local_socklen = c->local_socklen; sc->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); + sc->start_time = c->start_time; sc->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; sc->recv = ngx_quic_stream_recv; @@ -699,9 +707,16 @@ ngx_quic_create_stream(ngx_connection_t *c, uint64_t id) if ((id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0 || (id & NGX_QUIC_STREAM_SERVER_INITIATED)) { + sc->write->active = 1; sc->write->ready = 1; } + if ((id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0 + || (id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0) + { + sc->read->active = 1; + } + if (id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { qs->send_max_data = qc->ctp.initial_max_stream_data_uni; @@ -797,7 +812,6 @@ ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, size_t size) || qs->recv_state == NGX_QUIC_STREAM_RECV_RESET_READ) { qs->recv_state = NGX_QUIC_STREAM_RECV_RESET_READ; - rev->error = 1; return NGX_ERROR; } @@ -1375,6 +1389,7 @@ ngx_int_t ngx_quic_handle_reset_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f) { + ngx_event_t *rev; ngx_quic_stream_t *qs; ngx_quic_connection_t *qc; @@ -1431,7 +1446,10 @@ ngx_quic_handle_reset_stream_frame(ngx_connection_t *c, return ngx_quic_close_stream(qs); } - ngx_quic_set_event(qs->connection->read); + rev = qs->connection->read; + rev->error = 1; + + ngx_quic_set_event(rev); return NGX_OK; } @@ -1745,31 +1763,3 @@ ngx_quic_set_event(ngx_event_t *ev) ngx_post_event(ev, &ngx_posted_events); } } - - -ngx_int_t -ngx_quic_handle_read_event(ngx_event_t *rev, ngx_uint_t flags) -{ - if (!rev->active && !rev->ready) { - rev->active = 1; - - } else if (rev->active && (rev->ready || (flags & NGX_CLOSE_EVENT))) { - rev->active = 0; - } - - return NGX_OK; -} - - -ngx_int_t -ngx_quic_handle_write_event(ngx_event_t *wev, size_t lowat) -{ - if (!wev->active && !wev->ready) { - wev->active = 1; - - } else if (wev->active && wev->ready) { - wev->active = 0; - } - - return NGX_OK; -} diff --git a/src/http/v3/ngx_http_v3_request.c b/src/http/v3/ngx_http_v3_request.c index f051989..7bf6145 100644 --- a/src/http/v3/ngx_http_v3_request.c +++ b/src/http/v3/ngx_http_v3_request.c @@ -165,7 +165,6 @@ ngx_http_v3_init_request_stream(ngx_connection_t *c) { 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; @@ -199,12 +198,10 @@ ngx_http_v3_init_request_stream(ngx_connection_t *c) return; } - 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) + || ngx_current_msec - c->start_time > clcf->keepalive_time) { h3c->goaway = 1; @@ -554,10 +551,16 @@ ngx_http_v3_process_request(ngx_event_t *rev) if (rc == NGX_BUSY) { if (rev->error) { - ngx_http_close_request(r, NGX_HTTP_CLOSE); + ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); break; } + if (!rev->timer_set) { + cscf = ngx_http_get_module_srv_conf(r, + ngx_http_core_module); + ngx_add_timer(rev, cscf->client_header_timeout); + } + if (ngx_handle_read_event(rev, 0) != NGX_OK) { ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); }