<< Back to previous view

[CMEMOIZE-5] Race condition occasionally generates NullPointerException when using memo-ttl Created: 31/May/13  Updated: 26/Jul/13  Resolved: 17/Jun/13

Status: Resolved
Project: core.memoize
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: James Reeves Assignee: Fogus
Resolution: Completed Votes: 0
Labels: None

Patch: Code


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)))

Comment by Fogus [ 03/Jun/13 1:48 PM ]

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

Comment by Fogus [ 17/Jun/13 12:54 PM ]

Fixed in version 0.5.4+.

Generated at Sat Jan 20 09:41:27 CST 2018 using JIRA 4.4#649-r158309.