Lukasz Lenart created WW-5716:
---------------------------------
Summary: Bound the per-locale definition caches in the Tiles plugin
Key: WW-5716
URL: https://issues.apache.org/jira/browse/WW-5716
Project: Struts 2
Issue Type: Improvement
Reporter: Lukasz Lenart
The Tiles plugin caches parsed definitions per resolved {{Locale}} in two maps
that grow without limit and are never reduced during the lifetime of the web
application:
*
{{org.apache.tiles.core.definition.dao.CachingLocaleUrlDefinitionDAO#locale2definitionMap}}
— a {{HashMap}} keyed by {{Locale}}, populated on each cache miss and never
evicted. It is only cleared when {{checkRefresh}} is enabled and a refresh is
required, and {{checkRefresh}} is {{false}} by default.
*
{{org.apache.tiles.core.definition.pattern.AbstractPatternDefinitionResolver#localePatternPaths}}
— populated via {{computeIfAbsent}} per locale customization key and never
swept.
The {{TilesContainer}} that holds the DAO is stored in application scope, so
both maps persist for the lifetime of the web application. With the default
{{StrutsTilesLocaleResolver}}, the resolved locale comes from the
{{ActionContext}} locale, which derives from {{request.getLocale()}}. In that
setup the number of distinct cache keys is bounded only by the number of
distinct locales encountered, and every new locale adds an entry that is
retained indefinitely, so the caches' memory footprint grows over time with no
upper bound.
h3. Proposed change
Bound both per-locale maps in the plugin's vendored Tiles code — for example a
configurable maximum size with eviction — and ensure {{localePatternPaths}} is
bounded/cleared alongside {{locale2definitionMap}}. Both maps sit on the same
code path, so they must be bounded together; fixing only one leaves the other
unbounded.
h3. Notes
* Affects every version that ships the Tiles plugin; the vendored caching DAO
is unbounded across all of them.
* Deployments that pin a fixed locale via {{struts.locale}}, or that enable
{{struts.locale.validateRequestLocale=true}} (7.3.0+/6.11.0+), already
constrain the key set. This change makes the plugin robust by default without
requiring that configuration.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)