Welcome! Log In Create A New Profile

Advanced

[nginx] gRPC: disabled keepalive when sending control frames was blocked.

Maxim Dounin
December 04, 2018 08:38AM
details: https://hg.nginx.org/nginx/rev/dc69f7aa6ca6
branches: stable-1.14
changeset: 7417:dc69f7aa6ca6
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Sep 03 19:34:02 2018 +0300
description:
gRPC: disabled keepalive when sending control frames was blocked.

If sending request body was not completed (u->request_body_sent is not set),
the upstream keepalive module won't save such a connection. However, it
is theoretically possible (though highly unlikely) that sending of some
control frames can be blocked after the request body was sent. The
ctx->output_blocked flag introduced to disable keepalive in such cases.

diffstat:

src/http/modules/ngx_http_grpc_module.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)

diffs (57 lines):

diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -112,6 +112,7 @@ typedef struct {

unsigned header_sent:1;
unsigned output_closed:1;
+ unsigned output_blocked:1;
unsigned parsing_headers:1;
unsigned end_stream:1;
unsigned done:1;
@@ -1076,6 +1077,7 @@ ngx_http_grpc_reinit_request(ngx_http_re
ctx->state = 0;
ctx->header_sent = 0;
ctx->output_closed = 0;
+ ctx->output_blocked = 0;
ctx->parsing_headers = 0;
ctx->end_stream = 0;
ctx->done = 0;
@@ -1413,6 +1415,13 @@ ngx_http_grpc_body_output_filter(void *d
rc = NGX_AGAIN;
}

+ if (rc == NGX_AGAIN) {
+ ctx->output_blocked = 1;
+
+ } else {
+ ctx->output_blocked = 0;
+ }
+
if (ctx->done) {

/*
@@ -1427,6 +1436,7 @@ ngx_http_grpc_body_output_filter(void *d
if (ctx->in == NULL
&& ctx->out == NULL
&& ctx->output_closed
+ && !ctx->output_blocked
&& ctx->state == ngx_http_grpc_st_start)
{
u->keepalive = 1;
@@ -1777,6 +1787,7 @@ ngx_http_grpc_process_header(ngx_http_re
if (ctx->in == NULL
&& ctx->out == NULL
&& ctx->output_closed
+ && !ctx->output_blocked
&& b->last == b->pos)
{
u->keepalive = 1;
@@ -1879,6 +1890,7 @@ ngx_http_grpc_filter(void *data, ssize_t

if (ctx->in == NULL
&& ctx->output_closed
+ && !ctx->output_blocked
&& ctx->state == ngx_http_grpc_st_start)
{
u->keepalive = 1;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] gRPC: disabled keepalive when sending control frames was blocked.

Maxim Dounin 366 December 04, 2018 08:38AM



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

Online Users

Guests: 266
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