Fork me on GitHub
#clara
<
2021-03-26
>
Pieter Slabbert09:03:28

I think I have found a memory leak in clara when calling mk-session. I have been trying to find a memory leak in one of our services. I eventually found that the leak was from mk-session. This service creates lots of rules dynamically so initially I assumed it was that. I saw the :cache option in mk-session and thought that we were probably caching all those dynamically created rules, however turning off the cache did not help. I eventually created this minimal code to reproduce the leak. With cache false this leaks, with cache true it doesn't, but when adding in dynamically created rules the cache true also leaks, even after calling clear-session-cache!

(ns mem-leak
  (:require [clara.rules :refer [mk-session defquery]]))
(defquery get-status [:?status] [?result <- :status [{status :status}] (= status ?status)])
(defquery get-all-status [] [?result <- :status])

(doseq [i (range 10000)]
    (mk-session 'mem-leak
                :cache false)) 

Linus Ericsson13:03:04

Good finding! Have you created an issue in the clara-rules github repo? https://github.com/cerner/clara-rules/issues

Pieter Slabbert13:03:21

I haven't yet, I'm still busy digging into it, going to create the issue soon

👍 1
ethanc13:03:21

Is this is the Clojure side or the clojurescript side? My gut says clojure, but i just wanted to make sure

ethanc13:03:44

At first blush, my mind goes to the nature of mk-session. Its usage of eval generates classes on the fly, and i have to wonder if those classes are unable to be freed for some reason…. I will have to find time to look into this

👍 1
Pieter Slabbert13:03:16

I didn't end up finding anything else useful, so I have just created the ticket https://github.com/cerner/clara-rules/issues/468

❤️ 1
👍 2