Comments (6)
@sumbach Thanks for pinging about this Sam 👍
Have just added 36c8cdf - please take a moment to double check if you're happy with the approach there?
Specifically, we had a failing assert (which throws AssertionError). It looks like :pre function preconditions also throw AssertionError as well.
Yes, this is unfortunately a bit of a common gotcha. Contrary to popular advice, I generally prefer catching Throwable
for this reason. And it's also one of the reasons that I prefer throwing ExceptionInfo
s for Truss, etc.
from http-kit.
One comment on the approach: You could allocate and initialize the HeaderMap
in an instance-level (or class static) constant.
I was thinking about the possibility of catching OutOfMemoryError
, in which case you'd want to avoid allocations along this code path. But it looks like HttpEncode
has to allocate ByteBuffer
s (among other things), so there's probably no benefit to avoiding this HeaderMap
allocation "just in case" we get an OOM.
That said, a constant HeaderMap
(or dedicated factory function / constructor) could make this code marginally more readable:
cb.run(HttpEncode(503, ContentTypeTextPlain, "Server unavailable, please try again", this.serverHeader))
from http-kit.
One comment on the approach: You could allocate and initialize the HeaderMap in an instance-level (or class static) constant.
Done, thanks Sam 👍 I've just released v2.8.0-RC1 which includes this work.
Cheers!
from http-kit.
Thank you, @ptaoussanis 😀 👍
from http-kit.
I only noticed the "missing" Content-Type header because my ring middleware is only catching Exception
and some non-Exception
throwables were sneaking through to org.httpkit.server.HttpHandler#run
.
Specifically, we had a failing assert
(which throws AssertionError
). It looks like :pre
function preconditions also throw AssertionError
as well.
Arguably, these should throw some appropriate Exception
instead of AssertionError
(which should be reserved for coding errors), but it's not implausible to encounter a non-Exception
in the wild -- maybe IOError
?
from http-kit.
✨✨ @ptaoussanis ✨✨
This is amazing!! I just tested with a local http-kit build (commit e5b69e1) and confirmed that my errant AssertionError
now yields HTTP 500 with Content-Type: text/plain; charset=utf-8
👍 💯 😀
The advice I've heard against catching Throwable
is that it's often pointless to catch and attempt to handle many JVM-initiated exceptions (like OutOfMemoryError
) -- probably better to let the thread, and perhaps even the whole JVM process, crash on "unrecoverable" exceptions.
But when user code throws non-Exception
, how can we distinguish between these and "unrecoverable" exceptions? I don't think we have a better choice than catching Throwable
.
For my part, I will avoid assert
(and defn
+:pre
?) for anything related to user input --
I'll take your suggestion to throw some appropriate unchecked RuntimeException
(like ExceptionInfo
).
from http-kit.
Related Issues (20)
- Race condition in TimerService.scheduleTask HOT 2
- Ring websocket API support HOT 4
- Problem in native-image and HttpUtils when using virtual threads HOT 11
- 2.8.0-beta2 has CIDER dependencies HOT 3
- CURL and finagle failing to parse :set-cookies with '\n' HOT 13
- Unix socket benchmark HOT 1
- It will turn headers into camel format HOT 2
- logger-warn gets rebound HOT 1
- logger-warn and error-warn are passed in wrong order to HttpServer constructor HOT 1
- Requests which throw java.net.ConnectException may actually succeed HOT 3
- Request Map doesn't contain information about authority HOT 8
- http-kit v2.8.0-RC1 HOT 1
- http-kit v2.8.0 final HOT 1
- v2.7.0 SNI change broke connections to plain IP addresses with SSLHandshakeException "Hostname or IP address is undefined." HOT 8
- Add options for encoding nested form and query params a la clj-http HOT 7
- WebTransport support HOT 2
- NoSuchMethodError on projects AOT'd on java 21 but run on earlier java versions HOT 13
- [Proposal][Client] Consider more idiomatic bridges with JVM async paradigms HOT 5
- "Unmasked client to server frame" causes 502s HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-kit.