The official NGINX Open Source repository.
Go to file
Maxim Dounin 6f2059147f Upstream: fixed usage of closed sockets with filter finalization.
When filter finalization is triggered when working with an upstream server,
and error_page redirects request processing to some simple handler,
ngx_http_request_finalize() triggers request termination when the response
is sent.  In particular, via the upstream cleanup handler, nginx will close
the upstream connection and the corresponding socket.

Still, this can happen to be with ngx_event_pipe() on stack.  While
the code will set p->downstream_error due to NGX_ERROR returned from the
output filter chain by filter finalization, otherwise the error will be
ignored till control returns to ngx_http_upstream_process_request().
And event pipe might try reading from the (already closed) socket, resulting
in "readv() failed (9: Bad file descriptor) while reading upstream" errors
(or even segfaults with SSL).

Such errors were seen with the following configuration:

    location /t2 {
        proxy_pass http://127.0.0.1:8080/big;

        image_filter_buffer 10m;
        image_filter   resize  150 100;
        error_page     415   = /empty;
    }

    location /empty {
        return 204;
    }

    location /big {
        # big enough static file
    }

Fix is to clear p->upstream in ngx_http_upstream_finalize_request(),
and ensure that p->upstream is checked in ngx_event_pipe_read_upstream()
and when handling events at ngx_event_pipe() exit.
2024-01-30 03:20:10 +03:00
auto SSL: avoid using OpenSSL config in build directory (ticket #2404). 2023-06-21 01:29:53 +03:00
conf MIME: added image/avif type. 2021-10-25 20:49:15 +03:00
contrib Contrib: vim syntax, update core and 3rd party module directives. 2023-07-24 18:04:41 +03:00
docs nginx-1.25.3-RELEASE 2023-10-24 16:46:46 +03:00
misc Updated OpenSSL and zlib used for win32 builds. 2023-10-23 21:50:26 +03:00
src Upstream: fixed usage of closed sockets with filter finalization. 2024-01-30 03:20:10 +03:00
.hgtags release-1.25.3 tag 2023-10-24 16:46:47 +03:00