comparison src/http/modules/ngx_http_grpc_module.c @ 7350:67c6cb7f477c

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 03 Sep 2018 19:34:02 +0300
parents f6047a579ca1
children 8b68d50090e4
comparison
equal deleted inserted replaced
7349:f6047a579ca1 7350:67c6cb7f477c
107 unsigned literal:1; 107 unsigned literal:1;
108 unsigned field_huffman:1; 108 unsigned field_huffman:1;
109 109
110 unsigned header_sent:1; 110 unsigned header_sent:1;
111 unsigned output_closed:1; 111 unsigned output_closed:1;
112 unsigned output_blocked:1;
112 unsigned parsing_headers:1; 113 unsigned parsing_headers:1;
113 unsigned end_stream:1; 114 unsigned end_stream:1;
114 unsigned done:1; 115 unsigned done:1;
115 unsigned status:1; 116 unsigned status:1;
116 117
1071 } 1072 }
1072 1073
1073 ctx->state = 0; 1074 ctx->state = 0;
1074 ctx->header_sent = 0; 1075 ctx->header_sent = 0;
1075 ctx->output_closed = 0; 1076 ctx->output_closed = 0;
1077 ctx->output_blocked = 0;
1076 ctx->parsing_headers = 0; 1078 ctx->parsing_headers = 0;
1077 ctx->end_stream = 0; 1079 ctx->end_stream = 0;
1078 ctx->done = 0; 1080 ctx->done = 0;
1079 ctx->status = 0; 1081 ctx->status = 0;
1080 ctx->connection = NULL; 1082 ctx->connection = NULL;
1408 1410
1409 if (rc == NGX_OK && ctx->in) { 1411 if (rc == NGX_OK && ctx->in) {
1410 rc = NGX_AGAIN; 1412 rc = NGX_AGAIN;
1411 } 1413 }
1412 1414
1415 if (rc == NGX_AGAIN) {
1416 ctx->output_blocked = 1;
1417
1418 } else {
1419 ctx->output_blocked = 0;
1420 }
1421
1413 if (ctx->done) { 1422 if (ctx->done) {
1414 1423
1415 /* 1424 /*
1416 * We have already got the response and were sending some additional 1425 * We have already got the response and were sending some additional
1417 * control frames. Even if there is still something unsent, stop 1426 * control frames. Even if there is still something unsent, stop
1422 u->length = 0; 1431 u->length = 0;
1423 1432
1424 if (ctx->in == NULL 1433 if (ctx->in == NULL
1425 && ctx->out == NULL 1434 && ctx->out == NULL
1426 && ctx->output_closed 1435 && ctx->output_closed
1436 && !ctx->output_blocked
1427 && ctx->state == ngx_http_grpc_st_start) 1437 && ctx->state == ngx_http_grpc_st_start)
1428 { 1438 {
1429 u->keepalive = 1; 1439 u->keepalive = 1;
1430 } 1440 }
1431 1441
1772 u->headers_in.content_length_n = 0; 1782 u->headers_in.content_length_n = 0;
1773 1783
1774 if (ctx->in == NULL 1784 if (ctx->in == NULL
1775 && ctx->out == NULL 1785 && ctx->out == NULL
1776 && ctx->output_closed 1786 && ctx->output_closed
1787 && !ctx->output_blocked
1777 && b->last == b->pos) 1788 && b->last == b->pos)
1778 { 1789 {
1779 u->keepalive = 1; 1790 u->keepalive = 1;
1780 } 1791 }
1781 } 1792 }
1874 1885
1875 u->length = 0; 1886 u->length = 0;
1876 1887
1877 if (ctx->in == NULL 1888 if (ctx->in == NULL
1878 && ctx->output_closed 1889 && ctx->output_closed
1890 && !ctx->output_blocked
1879 && ctx->state == ngx_http_grpc_st_start) 1891 && ctx->state == ngx_http_grpc_st_start)
1880 { 1892 {
1881 u->keepalive = 1; 1893 u->keepalive = 1;
1882 } 1894 }
1883 1895