Uploaded image for project: 'core.cache'
  1. CCACHE-32

LIRSCache defect allows it's memory use to grow without bound

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Labels:
      None

      Description

      Hello! I was messing around with the LIRSCache and ran into what I think is a bug.

      https://github.com/clojure/core.cache/blob/master/src/main/clojure/clojure/core/cache.clj#L371

      In the case of a bunch of misses on unique keys, then the stack S will grow without bound and violate the limit that you give it.

      (def C (cache/lirs-cache-factory {} :s-history-limit 2 :q-history-limit 1))
      (defn populate [n] (let [pairs (map (fn [x] [x x]) (range n))] (reduce (fn [cache [k v]] (cache/miss cache k v)) C pairs)))
      (.toString (populate 10))
      "{9 9, 1 1, 0 0}, {0 1, 1 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8 9, 9 10}, {9 10}, 10, 2, 1"
      

      You can see that the S stack is growing without bound, and if you do (populate 1000), then it is 1000 pieces large.

      I'm not sure what the desired outcome is, but any time we add something to one of the queues, we need to make sure that we're doing the right thing with what is kicked out, unless I'm misinterpreting things.

      Thanks for making Clojure awesome!

        Attachments

          Activity

            People

            • Assignee:
              seancorfield Sean Corfield
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: