Fork me on GitHub
Mor Gazith16:06:53

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]
        (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:
indefinitely. any ideas what is going on here?

Jan K18:06:29

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

Jan K18:06:01

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

Mor Gazith18:06:31

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

Jan K18:06:50

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

Mor Gazith06:06:09

I’ve verified the loop is not coming from the caller of outer-function> but definitely the core.async/go is doing something funky. i’ve added another print just before the go and it’s only printed once, and then “before” is printed repeatedly. so go can’t handle a throwable thrown in its form? it just retries the form over and over again?


What version of core.async?


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 Gazith06:06:47

core.async 0.2.395


That is, I believe, a wicked old version


0.7.559 has the fixed exception handling, and 1.3.618 is the latest release

Mor Gazith10:06:34

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