comparison src/http/modules/ngx_http_grpc_module.c @ 7872:021416fca094

gRPC: handling GOAWAY with a higher last stream identifier. Previously, once received from upstream, it couldn't limit opening additional streams in a cached keepalive connection.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 17 Jun 2021 11:43:55 +0300
parents 3ab8e1e2f0f7
children 0302a4f0b6c4
comparison
equal deleted inserted replaced
7871:5f765427c17a 7872:021416fca094
119 unsigned parsing_headers:1; 119 unsigned parsing_headers:1;
120 unsigned end_stream:1; 120 unsigned end_stream:1;
121 unsigned done:1; 121 unsigned done:1;
122 unsigned status:1; 122 unsigned status:1;
123 unsigned rst:1; 123 unsigned rst:1;
124 unsigned goaway:1;
124 125
125 ngx_http_request_t *request; 126 ngx_http_request_t *request;
126 127
127 ngx_str_t host; 128 ngx_str_t host;
128 } ngx_http_grpc_ctx_t; 129 } ngx_http_grpc_ctx_t;
1208 ctx->parsing_headers = 0; 1209 ctx->parsing_headers = 0;
1209 ctx->end_stream = 0; 1210 ctx->end_stream = 0;
1210 ctx->done = 0; 1211 ctx->done = 0;
1211 ctx->status = 0; 1212 ctx->status = 0;
1212 ctx->rst = 0; 1213 ctx->rst = 0;
1214 ctx->goaway = 0;
1213 ctx->connection = NULL; 1215 ctx->connection = NULL;
1214 1216
1215 return NGX_OK; 1217 return NGX_OK;
1216 } 1218 }
1217 1219
1563 1565
1564 if (ctx->in == NULL 1566 if (ctx->in == NULL
1565 && ctx->out == NULL 1567 && ctx->out == NULL
1566 && ctx->output_closed 1568 && ctx->output_closed
1567 && !ctx->output_blocked 1569 && !ctx->output_blocked
1570 && !ctx->goaway
1568 && ctx->state == ngx_http_grpc_st_start) 1571 && ctx->state == ngx_http_grpc_st_start)
1569 { 1572 {
1570 u->keepalive = 1; 1573 u->keepalive = 1;
1571 } 1574 }
1572 1575
1712 ctx->error); 1715 ctx->error);
1713 1716
1714 return NGX_HTTP_UPSTREAM_INVALID_HEADER; 1717 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1715 } 1718 }
1716 1719
1720 ctx->goaway = 1;
1721
1717 continue; 1722 continue;
1718 } 1723 }
1719 1724
1720 if (ctx->type == NGX_HTTP_V2_WINDOW_UPDATE_FRAME) { 1725 if (ctx->type == NGX_HTTP_V2_WINDOW_UPDATE_FRAME) {
1721 1726
1905 1910
1906 if (ctx->in == NULL 1911 if (ctx->in == NULL
1907 && ctx->out == NULL 1912 && ctx->out == NULL
1908 && ctx->output_closed 1913 && ctx->output_closed
1909 && !ctx->output_blocked 1914 && !ctx->output_blocked
1915 && !ctx->goaway
1910 && b->last == b->pos) 1916 && b->last == b->pos)
1911 { 1917 {
1912 u->keepalive = 1; 1918 u->keepalive = 1;
1913 } 1919 }
1914 } 1920 }
2033 u->length = 0; 2039 u->length = 0;
2034 2040
2035 if (ctx->in == NULL 2041 if (ctx->in == NULL
2036 && ctx->output_closed 2042 && ctx->output_closed
2037 && !ctx->output_blocked 2043 && !ctx->output_blocked
2044 && !ctx->goaway
2038 && ctx->state == ngx_http_grpc_st_start) 2045 && ctx->state == ngx_http_grpc_st_start)
2039 { 2046 {
2040 u->keepalive = 1; 2047 u->keepalive = 1;
2041 } 2048 }
2042 2049
2201 "upstream sent goaway with error %ui", 2208 "upstream sent goaway with error %ui",
2202 ctx->error); 2209 ctx->error);
2203 2210
2204 return NGX_ERROR; 2211 return NGX_ERROR;
2205 } 2212 }
2213
2214 ctx->goaway = 1;
2206 2215
2207 continue; 2216 continue;
2208 } 2217 }
2209 2218
2210 if (ctx->type == NGX_HTTP_V2_WINDOW_UPDATE_FRAME) { 2219 if (ctx->type == NGX_HTTP_V2_WINDOW_UPDATE_FRAME) {