core-async

Mor Gazith 2021-06-20T16:57:53.085900Z

not sure if this is the best place to post this… something weird is happening with a combination of go + try + <! + :pre here’s a minimal POC:

(defn inner-function
  [{:keys [param]}]
  {:pre [param]}
  (println "in second function param=" param))

(defn outer-function> [{:keys [param]} req]
  (clojure.core.async/go
    (try
        (println "before")
        (clojure.core.async/<! (inner-function {:param param}))
        (println "after ")
      (catch Exception e
        {:status 500
         :error  "Something happened"}))))
when calling outer-function> with param nil the precondition check will fail which is expected, but instead of returning an error message, there’s an infinite-loop that eventually crashes the service - printing:
before
before
before
... 
indefinitely. any ideas what is going on here?

Jan K 2021-06-20T18:26:29.086200Z

:pre/:post checks throw AssertionErrors, which will not be caught with "catch Exception", you'd need "catch Throwable"

Jan K 2021-06-20T18:27:01.086400Z

The loop must be caused by something that keeps calling outer-function>

Mor Gazith 2021-06-20T18:27:31.086600Z

thanks, I'll try that... I'll check if there's something that catches that throwable and keeps calling the outer function

Jan K 2021-06-20T18:40:50.086900Z

The AssertionError can't be caught by the caller, because it is lost in the go block thread.

2021-06-20T22:37:19.087400Z

What version of core.async?

2021-06-20T22:40:44.092400Z

The exception handling on the clojure side of core.async a complete rewrite, and some fixes to the rewrite, and at the moment I am not aware of any bugs in it (there used to be all kinds of bugs that could cause things like infinite loops on exceptions). The clojurescript side is still buggy (it got the rewrite but not the bug fixes for the rewrite)

Mor Gazith 2021-06-21T10:00:34.093400Z

updated to 0.7.559 and issue seems to be fixed, thanks!