﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
2384	http upstream cache and slicing leaks open files	Thibault VINCENT		"Using `proxy_cache_path` and `proxy_cache` with `slice` is causing a file descriptor exhaustion while serving subrequests, which leads to a worker crash.

Test configuration:
{{{
proxy_cache_path /mnt/cache levels=1:2 keys_zone=zone:100m
    max_size=500g min_free=10g inactive=4h use_temp_path=off;

server {
    listen 80 default_server reuseport backlog=4096;

    location / {
        add_header Cache-Control ""public, no-transform"";
        expires 1d;

        # low to trigger bug
        slice 1k;

        proxy_cache zone;
        proxy_cache_key $uri$slice_range;
        proxy_set_header Range $slice_range;

        proxy_http_version 1.1;
        proxy_set_header Connection """";
        proxy_pass_request_body off;
        proxy_pass http://192.168.123.123;
    }
}
}}}

Running with a limit of 1000 maximum open files, this proxy will crash when serving the 500th slice of so. It does not matter whether it's a 100% cache miss or hit situation.
I guess the root cause may be cache file descriptors left open till the main request is cleaned up.

{{{
[crit] 65993#0: *1 open() ""/mnt/cache/f/5c/4cca8c6cb531b0aaa5a2fe16f43d45cf.0000000996"" failed (24: Too many open files) while reading upstream, client: 127.0.0.1, server: server, request: ""GET /test HTTP/1.1"", subrequest: ""/test"", upstream: ""http://192.168.123.123/test"", host: ""127.0.0.1:80""
}}}

Is it a design limitation of the slice module, or could it be improved?

Thanks"	defect	closed	minor		nginx-core	1.23.x	invalid			Linux 5.19.4-200.fc36.x86_64	"nginx version: nginx/1.23.1
built by gcc 12.2.1 20220819 (Red Hat 12.2.1-1) (GCC) 
configure arguments: --without-http_rewrite_module --without-http_gzip_module --with-http_slice_module"
