apache / apache/shardingsphere

OrderedSPILoader may retain transient multi-object lookup keys

Open
#38,981 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

## Bug Report

`OrderedSPILoader` keeps a singleton-registry cache for multi-object lookups. The cache key is the input `Collection` itself.

When callers repeatedly pass newly created object collections, such as transient `RuleConfiguration` or `YamlRuleConfiguration` collections, semantically equivalent inputs may become different cache keys. Since the cache is held by the singleton SPI registry, these keys can retain the whole configuration object graph for the lifetime of the process.

This can cause continuous heap growth under workloads that repeatedly rebuild and convert rule configuration collections.

## Expected behavior

`OrderedSPILoader` should not retain transient object collections as long-lived cache keys.

For multi-object lookups, it should reuse stable class-based lookup results where possible and build the current object-keyed result without storing the transient input collection globally.

## Actual behavior

For singleton ordered SPI services, multi-object `getServices(...)` lookups are cached by the original input collection.

If the input contains newly allocated rule configuration objects, each call may add another long-lived cache entry, even if the logical rule types are the same.

## Impact

This may lead to unnecessary heap retention, frequent GC, and eventually OOM in metadata or management workloads that repeatedly load and convert database rule configurations.

## Related pull request

A proposed fix is available in:

- https://github.com/apache/shardingsphere/pull/38980

Contributor guide

Open the contributing guide

Research direction

Start at OrderedSPILoader and trace the singleton-registry cache used by multi-object getServices(...) lookups. Verify how transient input collections become cache keys, then confirm that stable class-based results are reused without retaining the current collection; existing tests and the proposed pull request should show the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.