Skip to content

expirable-lru: Add() replaces existing entry without calling evict callback? #189

@shellohunter

Description

@shellohunter

run into a memleak issue with expirable LRU.
here's the scenario:
there's a chance that Get() returns nothing, but Contains() return true, which means the entry has expired, ready for eviction, but not done yet. then, at the same time, another Add() with the same key was called.

  • what expirable LRU does now: the old entry was overwrite silently. which may lead to serious leakage, since the entry may holding some important resource needs to release in the eviction callback.
  • expected behavior: old entry get removed with its eviction callback called.

found a similar issue: #135,
I guess that's why new APIs like ContainsOrAdd were introduced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions