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?:pre/:post checks throw AssertionErrors, which will not be caught with "catch Exception", you'd need "catch Throwable"
The loop must be caused by something that keeps calling outer-function>
thanks, I'll try that... I'll check if there's something that catches that throwable and keeps calling the outer function
The AssertionError can't be caught by the caller, because it is lost in the go block thread.
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)
updated to 0.7.559 and issue seems to be fixed, thanks!