Consider the following code returning an ISeq body that throws after some iterations:
(defn now-millis [] (str "data:" (System/currentTimeMillis) "\n\n"))
(def counter (atom 0))
(defn now-throw []
(swap! counter inc)
(if (< @counter 5000) "" (throw (ex-info "Test exception" {}))))
(def body (->> (repeat now-millis)
(interpose now-throw)
(map (fn [f] (f)))
lazy-seq))
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/event-stream"
"Cache-Control" "no-cache"
"Connection" "keep-alive"}
:body body})
When I use Curl (acceptable result):
$ curl localhost:8082
data:1751448129717
data:1751448129717
...
...
curl: (18) transfer closed with outstanding read data remaining
At the server end, I see this exception logged (acceptable result):
[qtp1107779742-52] WARN org.eclipse.jetty.ee9.nested.HttpChannel - /
clojure.lang.ExceptionInfo: Test exception {}
<stack-trace>
The issue is: I do not have control over how to perform cleanup actions when such an exception is thrown.