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

Hide
Fogus added a comment -

Version 0.5.4 should fix this problem. I added a regression test based on your snippet above.

Show
Fogus added a comment - Version 0.5.4 should fix this problem. I added a regression test based on your snippet above.
Hide
Fogus added a comment - - edited

Fixed in version 0.5.4+.

Show
Fogus added a comment - - edited Fixed in version 0.5.4+.
Fogus made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Alex Miller made changes -
Patch None [ 10000 ] Code [ 10001 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: