Skip to content

Fix PooledHashMap dropping live entries when an entry is removed during forEach#8499

Open
abdessattar23 wants to merge 1 commit into
open-telemetry:mainfrom
abdessattar23:fix/pooled-hashmap-issue
Open

Fix PooledHashMap dropping live entries when an entry is removed during forEach#8499
abdessattar23 wants to merge 1 commit into
open-telemetry:mainfrom
abdessattar23:fix/pooled-hashmap-issue

Conversation

@abdessattar23

Copy link
Copy Markdown
Contributor

Noticed PooledHashMap.forEach can skip an entry if the callback removes the one it's currently on. It walks each bucket by index, so remove() shifts the next entry into the current slot and i++ jumps over it

This bites AsynchronousMetricStorage in REUSABLE_DATA mode: during collection it removes stale series while iterating, so a live series sharing a bucket with a stale one can get dropped from that cycle. For cumulative async that shows up as a gap then a jump in the output. (IMMUTABLE_DATA uses ConcurrentHashMap and was fine. The code comment even says the map was picked to allow removal during iteration, it just wasn't holding up)

Fix: iterate each bucket back-to-front so removing the current entry only shifts already-visited ones. Added tests at the map level (collision plus remove-while-iterating) and the storage level (live series survive when stale ones drop)

@abdessattar23 abdessattar23 requested a review from a team as a code owner June 21, 2026 18:12
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 21, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: abdessattar23 / name: Mohammed Abdessetar Elyagoubi (dae39c2)

@abdessattar23 abdessattar23 force-pushed the fix/pooled-hashmap-issue branch from 9a1d1bb to dae39c2 Compare June 21, 2026 18:15
@abdessattar23 abdessattar23 force-pushed the fix/pooled-hashmap-issue branch from dae39c2 to 2d49da6 Compare June 21, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant