﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
2254	cache loader ignores reopen signal	mirek.chocholous.showmax.com@…		"Hi,
in our environment we use logrotate to rotate the logs regularly. We call `nginx -s reopen` after the logrotate and most of the times it works OK. The only exception is when nginx was restarted and cache loader is reading all the information about cached data from disk.

When cache loader is running it ignores the `nginx -s reopen` and keeps the file descriptor to the original log. When the rotated log file is deleted the disk space can't be released and that may lead to full log partition. 

Steps to reproduce:

# cat /etc/logrotate.d/cdn_nginx_access
/var/log/nginx/access.log {
  create 0640 www-data adm
  daily
  missingok
  nocopytruncate
  notifempty
  rotate 0
  sharedscripts
  postrotate
    nginx -s reopen>/dev/null 2>&1
  endscript
  prerotate
      if [ -d /etc/logrotate.d/httpd-prerotate ]; then     run-parts /etc/logrotate.d/httpd-prerotate;   fi

  endscript
}

# cat /etc/logrotate.d/cdn_nginx_other

/var/log/nginx/error.log {
  create 0640 www-data adm
  daily
  missingok
  nocompress
  nocopytruncate
  notifempty
  rotate 0
  sharedscripts
  postrotate
    nginx -s reopen>/dev/null 2>&1
  endscript
  prerotate
      if [ -d /etc/logrotate.d/httpd-prerotate ]; then     run-parts /etc/logrotate.d/httpd-prerotate;   fi

  endscript
}
# systemctl restart nginx
# lsof /var/log | grep delet
# logrotate -f /etc/logrotate.d/cdn_nginx_access
# logrotate -f /etc/logrotate.d/cdn_nginx_other
# lsof /var/log | grep delet
nginx     26823 www-data    2w   REG    9,2      711665  1835015 /var/log/nginx/error.log.1 (deleted)
nginx     26823 www-data    4w   REG    9,2  5831379042  1835014 /var/log/nginx/access.log.1 (deleted)
nginx     26823 www-data    5w   REG    9,2      711665  1835015 /var/log/nginx/error.log.1 (deleted)

# ps -efww | grep 26823
www-data 26823 26626  0 13:16 ?        00:00:01 nginx: cache loader process"	enhancement	new	minor		nginx-core	1.19.x		log reopen		Linux redacted.showmax.com 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux	"nginx version: nginx/1.20.0
built with OpenSSL 1.1.1d  10 Sep 2019
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/nginx --with-cc-opt='-O2 -g -O3 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -D_FORTIFY_SOURCE=2' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.20 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.10 --with-ld-opt='-Wl,-rpath,/opt/nginx/luajit/lib -fPIE' --sbin-path=/opt/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/opt/nginx/modules --http-client-body-temp-path=/opt/nginx/body --http-fastcgi-temp-path=/opt/nginx/fastcgi --http-proxy-temp-path=/opt/nginx/proxy --modules-path=/opt/nginx/modules --http-client-body-temp-path=/opt/nginx/body --http-fastcgi-temp-path=/opt/nginx/fastcgi --http-proxy-temp-path=/opt/nginx/proxy --with-threads --with-file-aio --with-http_v2_module --with-http_slice_module --with-http_realip_module --with-http_stub_status_module --add-module=/nginx/openresty/nginx-1.20.0.1/bundle/nginx-http-slice --add-module=/nginx/openresty/nginx-1.20.0.1/bundle/nginx-upstream-dynamic-servers --add-module=/nginx/openresty/nginx-1.20.0.1/bundle/nginx-module-vts --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module"
