comparison src/event/quic/ngx_event_quic.c @ 9049:2b4891fa0fbc quic

QUIC: made ngx_quic_finalize_connecion() more graceful. Previously, ngx_quic_finalize_connection() closed the connection with NGX_ERROR code, which resulted in immediate connection closure. Now the code is NGX_OK, which provides a more graceful shutdown with a timeout.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 22 Aug 2022 15:28:51 +0400
parents 9c427e98d8c1
children aaca8e111959
comparison
equal deleted inserted replaced
9048:9c427e98d8c1 9049:2b4891fa0fbc
412 ngx_quic_close_connection(c, NGX_DONE); 412 ngx_quic_close_connection(c, NGX_DONE);
413 return; 413 return;
414 } 414 }
415 415
416 if (c->close) { 416 if (c->close) {
417 qc->error = NGX_QUIC_ERR_NO_ERROR;
417 qc->error_reason = "graceful shutdown"; 418 qc->error_reason = "graceful shutdown";
418 ngx_quic_close_connection(c, NGX_OK); 419 ngx_quic_close_connection(c, NGX_OK);
419 return; 420 return;
420 } 421 }
421 422
504 */ 505 */
505 506
506 qc->error_level = c->ssl ? SSL_quic_read_level(c->ssl->connection) 507 qc->error_level = c->ssl ? SSL_quic_read_level(c->ssl->connection)
507 : ssl_encryption_initial; 508 : ssl_encryption_initial;
508 509
510 if (qc->error == (ngx_uint_t) -1) {
511 qc->error = NGX_QUIC_ERR_INTERNAL_ERROR;
512 qc->error_app = 0;
513 }
514
515 ngx_log_debug5(NGX_LOG_DEBUG_EVENT, c->log, 0,
516 "quic close immediate term:%d drain:%d "
517 "%serror:%ui \"%s\"",
518 rc == NGX_ERROR ? 1 : 0, qc->draining,
519 qc->error_app ? "app " : "", qc->error,
520 qc->error_reason ? qc->error_reason : "");
521
509 if (rc == NGX_OK) { 522 if (rc == NGX_OK) {
510 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
511 "quic close immediate drain:%d",
512 qc->draining);
513
514 qc->close.log = c->log; 523 qc->close.log = c->log;
515 qc->close.data = c; 524 qc->close.data = c;
516 qc->close.handler = ngx_quic_close_timer_handler; 525 qc->close.handler = ngx_quic_close_timer_handler;
517 qc->close.cancelable = 1; 526 qc->close.cancelable = 1;
518 527
519 ctx = ngx_quic_get_send_ctx(qc, qc->error_level); 528 ctx = ngx_quic_get_send_ctx(qc, qc->error_level);
520
521 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx)); 529 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
522
523 qc->error = NGX_QUIC_ERR_NO_ERROR;
524
525 } else {
526 if (qc->error == (ngx_uint_t) -1 && !qc->error_app) {
527 qc->error = NGX_QUIC_ERR_INTERNAL_ERROR;
528 }
529
530 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
531 "quic close immediate due to %serror: %ui %s",
532 qc->error_app ? "app " : "", qc->error,
533 qc->error_reason ? qc->error_reason : "");
534 } 530 }
535 531
536 (void) ngx_quic_send_cc(c); 532 (void) ngx_quic_send_cc(c);
537 533
538 if (qc->error_level == ssl_encryption_handshake) { 534 if (qc->error_level == ssl_encryption_handshake) {
615 qc->error = err; 611 qc->error = err;
616 qc->error_reason = reason; 612 qc->error_reason = reason;
617 qc->error_app = 1; 613 qc->error_app = 1;
618 qc->error_ftype = 0; 614 qc->error_ftype = 0;
619 615
620 ngx_quic_close_connection(c, NGX_ERROR); 616 ngx_quic_close_connection(c, NGX_OK);
621 } 617 }
622 618
623 619
624 void 620 void
625 ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err, 621 ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err,