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.
Maxim Dounin
3 years ago
111 | 111 | |
112 | 112 | unsigned header_sent:1; |
113 | 113 | unsigned output_closed:1; |
114 | unsigned output_blocked:1; | |
114 | 115 | unsigned parsing_headers:1; |
115 | 116 | unsigned end_stream:1; |
116 | 117 | unsigned done:1; |
1075 | 1076 | ctx->state = 0; |
1076 | 1077 | ctx->header_sent = 0; |
1077 | 1078 | ctx->output_closed = 0; |
1079 | ctx->output_blocked = 0; | |
1078 | 1080 | ctx->parsing_headers = 0; |
1079 | 1081 | ctx->end_stream = 0; |
1080 | 1082 | ctx->done = 0; |
1412 | 1414 | rc = NGX_AGAIN; |
1413 | 1415 | } |
1414 | 1416 | |
1417 | if (rc == NGX_AGAIN) { | |
1418 | ctx->output_blocked = 1; | |
1419 | ||
1420 | } else { | |
1421 | ctx->output_blocked = 0; | |
1422 | } | |
1423 | ||
1415 | 1424 | if (ctx->done) { |
1416 | 1425 | |
1417 | 1426 | /* |
1426 | 1435 | if (ctx->in == NULL |
1427 | 1436 | && ctx->out == NULL |
1428 | 1437 | && ctx->output_closed |
1438 | && !ctx->output_blocked | |
1429 | 1439 | && ctx->state == ngx_http_grpc_st_start) |
1430 | 1440 | { |
1431 | 1441 | u->keepalive = 1; |
1776 | 1786 | if (ctx->in == NULL |
1777 | 1787 | && ctx->out == NULL |
1778 | 1788 | && ctx->output_closed |
1789 | && !ctx->output_blocked | |
1779 | 1790 | && b->last == b->pos) |
1780 | 1791 | { |
1781 | 1792 | u->keepalive = 1; |
1878 | 1889 | |
1879 | 1890 | if (ctx->in == NULL |
1880 | 1891 | && ctx->output_closed |
1892 | && !ctx->output_blocked | |
1881 | 1893 | && ctx->state == ngx_http_grpc_st_start) |
1882 | 1894 | { |
1883 | 1895 | u->keepalive = 1; |