Skip to content

[ring-jetty-adapter] No control over exceptions thrown when obtaining item from ISeq response body #531

@kumarshantanu

Description

@kumarshantanu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions