core.memoize

Race condition occasionally generates NullPointerException when using memo-ttl

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

The build-memoizer function assumes that a lookup on the cache will never return nil, but in the case of a TTL cache, there is a small chance of this happening.

The problem occurs when the TTL cache expires between lines 129 and 130 in the build-memoizer function: https://github.com/clojure/core.memoize/blob/21d679df68044b11483ee9720911ff9e4d0ab9fd/src/main/clojure/clojure/core/memoize.clj#L130

This code snippet reproduces the issue:

(let [id (memo-ttl identity 100)]
  (dotimes [_ 1000000] (id 1)))

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: