Changeset 7235:c2a0a838c40f in nginx


Ignore:
Timestamp:
03/17/18 20:04:26 (2 years ago)
Author:
Maxim Dounin <mdounin@…>
Branch:
default
Phase:
public
Message:

gRPC: special handling of "trailer only" responses.

The gRPC protocol makes a distinction between HEADERS frame with
the END_STREAM flag set, and a HEADERS frame followed by an empty
DATA frame with the END_STREAM flag. The latter is not permitted,
and results in errors not being propagated through nginx. Instead,
gRPC clients complain that "server closed the stream without sending
trailers" (seen in grpc-go) or "13: Received RST_STREAM with error
code 2" (seen in grpc-c).

To fix this, nginx now returns HEADERS with the END_STREAM flag if
the response length is known to be 0, and we are not expecting
any trailer headers to be added. And the response length is
explicitly set to 0 in the gRPC proxy if we see initial HEADERS frame
with the END_STREAM flag set.

Location:
src/http
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/http/modules/ngx_http_grpc_module.c

    r7234 r7235  
    17441744                               "grpc header done");
    17451745
    1746                 if (ctx->end_stream
    1747                     && ctx->in == NULL
    1748                     && ctx->out == NULL
    1749                     && ctx->output_closed
    1750                     && b->last == b->pos)
    1751                 {
    1752                     u->keepalive = 1;
     1746                if (ctx->end_stream) {
     1747                    u->headers_in.content_length_n = 0;
     1748
     1749                    if (ctx->in == NULL
     1750                        && ctx->out == NULL
     1751                        && ctx->output_closed
     1752                        && b->last == b->pos)
     1753                    {
     1754                        u->keepalive = 1;
     1755                    }
    17531756                }
    17541757
  • src/http/v2/ngx_http_v2_filter_module.c

    r7229 r7235  
    137137    size_t                     len, tmp_len;
    138138    ngx_str_t                  host, location;
    139     ngx_uint_t                 i, port;
     139    ngx_uint_t                 i, port, fin;
    140140    ngx_list_part_t           *part;
    141141    ngx_table_elt_t           *header;
     
    644644    }
    645645
    646     frame = ngx_http_v2_create_headers_frame(r, start, pos, r->header_only);
     646    fin = r->header_only
     647          || (r->headers_out.content_length_n == 0 && !r->expect_trailers);
     648
     649    frame = ngx_http_v2_create_headers_frame(r, start, pos, fin);
    647650    if (frame == NULL) {
    648651        return NGX_ERROR;
     
    14381441    }
    14391442
    1440     if (in == NULL) {
     1443    if (in == NULL || stream->out_closed) {
    14411444
    14421445        if (stream->queued) {
Note: See TracChangeset for help on using the changeset viewer.