Cache: warn when cache_min_uses exceeds the uses bitfield range.

The "uses" counter on ngx_http_cache_node_t is a 10-bit field, so once
"{proxy,fastcgi,uwsgi,scgi}_cache_min_uses" is configured at 1024 or
greater the threshold can never be reached and caching is silently
disabled.  Emit a config-time warning at the point where the directive
is set so the misconfiguration is visible without code reading.
This commit is contained in:
Gabriel Clima 2026-05-05 05:53:30 +00:00
parent 1f57d8dc9d
commit abd92d41ec
4 changed files with 36 additions and 0 deletions

View file

@ -3166,6 +3166,15 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
if (conf->upstream.cache_min_uses != NGX_CONF_UNSET_UINT
&& conf->upstream.cache_min_uses > 1023)
{
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"fastcgi_cache_min_uses\" value %ui exceeds 1023 "
"and effectively disables caching",
conf->upstream.cache_min_uses);
}
ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
prev->upstream.cache_min_uses, 1);

View file

@ -3849,6 +3849,15 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
if (conf->upstream.cache_min_uses != NGX_CONF_UNSET_UINT
&& conf->upstream.cache_min_uses > 1023)
{
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"proxy_cache_min_uses\" value %ui exceeds 1023 "
"and effectively disables caching",
conf->upstream.cache_min_uses);
}
ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
prev->upstream.cache_min_uses, 1);

View file

@ -1579,6 +1579,15 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
if (conf->upstream.cache_min_uses != NGX_CONF_UNSET_UINT
&& conf->upstream.cache_min_uses > 1023)
{
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"scgi_cache_min_uses\" value %ui exceeds 1023 "
"and effectively disables caching",
conf->upstream.cache_min_uses);
}
ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
prev->upstream.cache_min_uses, 1);

View file

@ -1839,6 +1839,15 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
if (conf->upstream.cache_min_uses != NGX_CONF_UNSET_UINT
&& conf->upstream.cache_min_uses > 1023)
{
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"uwsgi_cache_min_uses\" value %ui exceeds 1023 "
"and effectively disables caching",
conf->upstream.cache_min_uses);
}
ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
prev->upstream.cache_min_uses, 1);