Skip to content

Commit 619cb99

Browse files
kachayevDerGuteMoritz
authored andcommitted
Suppress attempts to print huge and unreadable SSLHandshake exceptions
1 parent c56516e commit 619cb99

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/aleph/http/client.clj

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@
100100
nil))
101101
(no-url req))))
102102

103+
(defn exception-handler [ctx ex response-stream]
104+
(cond
105+
;; could happens when io.netty.handler.codec.http.HttpObjectAggregator
106+
;; is part of the pipeline
107+
(instance? TooLongFrameException ex)
108+
(s/put! response-stream ex)
109+
110+
;; when SSL handshake failed
111+
(http/ssl-handshake-error? ex)
112+
(let [^Throwable handshake-error (.getCause ^Throwable ex)]
113+
(s/put! response-stream handshake-error))
114+
115+
(not (instance? IOException ex))
116+
(log/warn ex "error in HTTP client")))
117+
103118
(defn raw-client-handler
104119
[response-stream buffer-capacity]
105120
(let [stream (atom nil)
@@ -117,8 +132,7 @@
117132

118133
:exception-caught
119134
([_ ctx ex]
120-
(when-not (instance? IOException ex)
121-
(log/warn ex "error in HTTP client")))
135+
(exception-handler ctx ex response-stream))
122136

123137
:channel-inactive
124138
([_ ctx]
@@ -169,14 +183,7 @@
169183

170184
:exception-caught
171185
([_ ctx ex]
172-
(cond
173-
; could happens when io.netty.handler.codec.http.HttpObjectAggregator
174-
; is part of the pipeline
175-
(instance? TooLongFrameException ex)
176-
(s/put! response-stream ex)
177-
178-
(not (instance? IOException ex))
179-
(log/warn ex "error in HTTP client")))
186+
(exception-handler ctx ex response-stream))
180187

181188
:channel-inactive
182189
([_ ctx]

src/aleph/http/core.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ByteBuf]
2424
[java.nio
2525
ByteBuffer]
26+
[io.netty.handler.codec DecoderException]
2627
[io.netty.handler.codec.http
2728
DefaultHttpRequest DefaultLastHttpContent
2829
DefaultHttpResponse DefaultFullHttpRequest
@@ -61,7 +62,8 @@
6162
ConcurrentLinkedQueue
6263
TimeUnit]
6364
[java.util.concurrent.atomic
64-
AtomicBoolean]))
65+
AtomicBoolean]
66+
[javax.net.ssl SSLHandshakeException]))
6567

6668
(def non-standard-keys
6769
(let [ks ["Content-MD5"
@@ -682,3 +684,7 @@
682684
(when (and (identical? ::ping-timeout v)
683685
(.isOpen ^Channel (.channel ctx)))
684686
(netty/close ctx))))))))
687+
688+
(defn ssl-handshake-error? [^Throwable ex]
689+
(and (instance? DecoderException ex)
690+
(instance? SSLHandshakeException (.getCause ex))))

src/aleph/http/server.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@
209209
(invalid-value-response req rsp))))))))))))
210210

211211
(defn exception-handler [ctx ex]
212-
(when-not (instance? IOException ex)
212+
(cond
213+
;; do not need to log an entire stack trace when SSL handshake failed
214+
(http/ssl-handshake-error? ex)
215+
(log/warn "SSL handshake failure:"
216+
(.getMessage ^Throwable (.getCause ^Throwable ex)))
217+
218+
(not (instance? IOException ex))
213219
(log/warn ex "error in HTTP server")))
214220

215221
(defn invalid-request? [^HttpRequest req]

0 commit comments

Comments
 (0)