Skip to content

Commit ca00d66

Browse files
authored
Merge pull request #611 from bevuta/tone-down-ssl-handshake-error-logging
Tone down SSL handshake error logging
2 parents 159d617 + 0fd5c89 commit ca00d66

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
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+
(netty/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/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+
(netty/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]

src/aleph/netty.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SslContext
3838
SslContextBuilder
3939
SslHandler]
40+
[io.netty.handler.codec DecoderException]
4041
[io.netty.handler.ssl.util
4142
SelfSignedCertificate InsecureTrustManagerFactory]
4243
[io.netty.resolver
@@ -76,7 +77,8 @@
7677
LoggingHandler
7778
LogLevel]
7879
[java.security.cert X509Certificate]
79-
[java.security PrivateKey]))
80+
[java.security PrivateKey]
81+
[javax.net.ssl SSLHandshakeException]))
8082

8183
;;;
8284

@@ -789,6 +791,11 @@
789791
^SslHandler (.get SslHandler)
790792
.engine
791793
.getSession))
794+
795+
(defn ssl-handshake-error? [^Throwable ex]
796+
(and (instance? DecoderException ex)
797+
(instance? SSLHandshakeException (.getCause ex))))
798+
792799
;;;
793800

794801
(defprotocol AlephServer

src/aleph/tcp.clj

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@
4242

4343
:exception-caught
4444
([_ ctx ex]
45-
(when-not (instance? IOException ex)
46-
(log/warn ex "error in TCP server")))
45+
(cond
46+
;; do not need to log an entire stack trace when SSL handshake failed
47+
(netty/ssl-handshake-error? ex)
48+
(log/warn "SSL handshake failure:"
49+
(.getMessage ^Throwable (.getCause ^Throwable ex)))
50+
51+
(not (instance? IOException ex))
52+
(log/warn ex "error in TCP server")))
4753

4854
:channel-inactive
4955
([_ ctx]
@@ -115,7 +121,11 @@
115121
:exception-caught
116122
([_ ctx ex]
117123
(when-not (d/error! d ex)
118-
(log/warn ex "error in TCP client")))
124+
(if (netty/ssl-handshake-error? ex)
125+
;; do not need to log an entire stack trace when SSL handshake failed
126+
(log/warn "SSL handshake failure:"
127+
(.getMessage ^Throwable (.getCause ^Throwable ex)))
128+
(log/warn ex "error in TCP client"))))
119129

120130
:channel-inactive
121131
([_ ctx]

0 commit comments

Comments
 (0)