Aarti Panchal created FINERACT-2981:
---------------------------------------
Summary: Hook lookup cache key ignores the event, so the wrong
hooks fire when the single-node cache is enabled
Key: FINERACT-2981
URL: https://issues.apache.org/jira/browse/FINERACT-2981
Project: Apache Fineract
Issue Type: Bug
Reporter: Aarti Panchal
HookReadPlatformServiceImpl.retrieveHooksByEvent(entityName, actionName) is
@Cacheable("hooks") with key = tenantIdentifier + 'HK'. Neither argument is in
the key, so with an explicit key Spring caches one list per tenant, but
HookRepository.findAllHooksListeningToEvent filters by entityName and
actionName.
FineractHookListener calls it after every write command (via
SynchronousCommandProcessingService.publishHookEvent), so the first command in
a tenant fills the cache and for the next minute (default TTL) every other
event gets that same hook list:
- hooks subscribed to event A fire for event B, with B's payload
- hooks for B never fire
- if the first command has no hooks, no hook fires for any event during that
minute
Only when the "hooks" cache is live, i.e. after switching to the single-node
cache (PUT /v1/caches with cacheType 2). On the default no-op cache nothing is
cached, which is why HookIntegrationTest and CI never see it.
Example: hook A on CLIENT/CREATE, hook B on LOAN/APPROVE, single-node cache on.
Create a client, then approve a loan within a minute: A fires for the loan
approval, B does not.
Fix: put the event in the key, e.g. getTenantIdentifier().concat('HK|' +
#entityName + '|' + #actionName). The @CacheEvict(allEntries = true) on hook
create/update/delete already clears all entries. A unit test with a
ConcurrentMapCacheManager can show the second event currently gets the first
event's hooks.
Found while working on FINERACT-2974 (hook update).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)