clara

http://www.clara-rules.org/
Pieter Slabbert 2021-03-26T09:34:28.001200Z

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 Ericsson 2021-03-26T13:06:04.001300Z

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

Pieter Slabbert 2021-03-26T13:07:21.001500Z

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

πŸ‘ 1
ethanc 2021-03-26T13:10:21.003200Z

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

Pieter Slabbert 2021-03-26T13:11:29.003300Z

clojure

πŸ‘ 1
Pieter Slabbert 2021-03-26T13:14:16.004Z

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

πŸ‘ 2
❀️ 1
ethanc 2021-03-26T13:22:44.004300Z

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