Opened 5 months ago

#2660 new defect

SSI is included twice when empty response is loaded from proxy cache

Reported by: 0x4a616e@… Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.24.x
Keywords: ssi proxy_cache Cc:
uname -a: Linux 20c2e793c008 6.6.31-linuxkit #1 SMP PREEMPT_DYNAMIC Wed Jun 5 07:37:32 UTC 2024 x86_64 Linux
nginx -V: nginx version: nginx/1.24.0
built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)
built with OpenSSL 3.0.7 1 Nov 2022 (running with OpenSSL 3.0.12 24 Oct 2023)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common

Description

Nginx includes a stub for an SSI twice when an empty response response from the upstream is loaded from proxy cache and there is at least one other SSI.

Consider the following example:

<html>
    <head><title>test</title></head>
    <body>
        <!--# include virtual="/non_empty/" -->

        <!--# block name="fallback" -->
            <div>I am a fallback</div>
        <!--# endblock -->

        <!-- START -->
        <!--# include virtual="/empty/" stub="fallback" -->
    </body>
</html>
  • The response of /non_empty/ will be 200 OK with non-empty response body
  • The response of /empty/ will be 200 OK with empty response body (Content-Length: 0)
  • The response of /empty/ is cached in a local proxy_cache

Then, the first response will be

<html>
    <head><title>test</title></head>
    <body>
        <div>i am not empty</div>



        <!-- START -->

            <div>I am a fallback</div>

    </body>
</html>

and the second response (using the proxy_cache) will be

<html>
    <head><title>test</title></head>
    <body>
        <div>i am not empty</div>



        <!-- START -->

            <div>I am a fallback</div>

            <div>I am a fallback</div>

    </body>
</html>
  • Adding wait="yes" to the include directives solves the issue.
  • Removing the proxy_cache solves the issue.

The nginx debug log is attached. You can see that the stub is included two times.

2024/06/19 09:16:00 [debug] 7#7: *5 ssi stub output: "/empty/?"
2024/06/19 09:16:00 [debug] 7#7: *5 ssi stub output: "/empty/?"

The issue seems to be introduced with 1.23.4 and is still present in 1.27.0. Version 1.23.3 does not have this issue.

The following project shows a complete example of the issue https://github.com/0x4a616e/nginx_ssi_issue/

Attachments (1)

debug.log (75.2 KB ) - added by 0x4a616e@… 5 months ago.
Debug log

Download all attachments as: .zip

Change History (1)

by 0x4a616e@…, 5 months ago

Attachment: debug.log added

Debug log

Note: See TracTickets for help on using tickets.