Bit of an advanced question. What's the best practice for handling exceptions when using async ring?
(try (respond ...) (catch Exception e (raise e)))
has a problem which I've just discovered: if respond throws (which I'm seeing in response to an EofException - the client has disconnected but the server is still writing). This then means you call raise and try to send a second response, which then throws a very loud exception.
From what I've seen, exception handling middleware seems to swap to respond if they have a handler for an exception (e.g. maybe you want to turn a FooException into {:status 200}). But this double write in the case of EofException leads to another exception due to the fact the response is already committed.
I don't want to update every exception handling middleware library (e.g. reitit) with EofException handling specifically. Although perhaps reitit should allow me to specify a way to "skip" a response for some exceptions and delegate back to the original raise. So it might be a slight tweak to how https://github.com/metosin/reitit/blob/310dcd0e9933237326d2648f19b23cbbd266de8b/modules/reitit-middleware/src/reitit/ring/middleware/exception.clj#L38-L42.https://github.com/ring-clojure/ring/issues/409 ah, just stumbled into this. So respond should never throw - but the one in ring.adapter.jetty can! I can probably fix that by wrapping our innermost respond and raise functions. This behaviour seems to be present on v1 and v2 of the jetty adapter. Would that be the recommended path to prevent this for now / is this something that should change upstream?
https://github.com/ring-clojure/ring/issues/535 issue opened.
Can you raise an issue for this? Under what circumstances does respond throw an exception? Also, please ignore the 2.0.0-alpha - that's a development dead end.
If the output stream is flushed, but the client has disconnected, then you get an EofException.
If you raise an issue for that, I'll try and get it fixed.