zen-lang / zen

Library for model driven systems
115 stars 12 forks source link

NullPointerException in zen.v2_validation/get-cached #40

Closed qdzo closed 1 year ago

qdzo commented 1 year ago

It looks like there are some concurrency issue with schema compilaiton.

In one of the test we encounter such issue when calling zen.v2_validation/validate.

#error {
 :cause Cannot invoke "clojure.lang.IFn.invoke(Object, Object, Object)" because "v" is null
 :via
 [{:type java.lang.NullPointerException
   :message Cannot invoke "clojure.lang.IFn.invoke(Object, Object, Object)" because "v" is null
   :at [zen.v2_validation$get_cached$fn__429 invoke v2_validation.clj 166]}]
 :trace
 [[zen.v2_validation$get_cached$fn__429 invoke v2_validation.clj 166]
  [zen.v2_validation$_STAR_validate_schema invokeStatic v2_validation.clj 204]
  [zen.v2_validation$_STAR_validate_schema invoke v2_validation.clj 194]
  [zen.v2_validation$validate invokeStatic v2_validation.clj 232]
  [zen.v2_validation$validate doInvoke v2_validation.clj 216]

When running test 2nd time - everything is ok. But after recreating zen-context - fail repeats.

For now I failed in making simple reproducible test case.

carbon-hvze commented 1 year ago

can you provide the example test case which fails occasionally ?

I think the issue may be related to schema definition

octoshikari commented 1 year ago

@carbon-hvze Same problem in another place. Please check schema below

 create-box
 {:zen/tags #{zenbox/rpc}
  :zen/desc "Create box"
  :params {:type zen/map
           :require #{:id :fhirVersion}
           :keys {:id           {:type zen/string :regex "^[a-z][a-z0-9]{4,}$"}
                  :fhirVersion  {:type zen/string :regex "^fhir-([1,3,4])\\.([0-4,8])\\.([0-2])$"}
                  :description  {:type zen/string}
                  :env          {:type zen/any}}}}
KGOH commented 1 year ago

Here's code reproducing the problem

(dotimes [_ 100]
    (def ztx (zen.core/new-context))

    (def lock (promise))

    (zen.core/load-ns ztx '{:ns myns
                            sym {:zen/tags #{zen/schema}
                                 :type zen/map
                                 :keys {:a {:type zen/string}}}})

    (def futures
      (mapv (fn [n]
              (future
                @lock
                (zen.core/validate ztx
                                   #{'myns/sym}
                                   {:a "1"})))
            [1 2]))

    (deliver lock :unlock)

    (mapv (fn [req-fut] @req-fut) futures))
qdzo commented 1 year ago

Problem is gone for us