Skip to content

Commit 5548a51

Browse files
committed
Don't invoke handler when connection closes during TLS handshake
Fixes #618.
1 parent d138d9f commit 5548a51

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/aleph/tcp.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@
6262
(-> ssl-handler
6363
.handshakeFuture
6464
netty/wrap-future
65-
(d/on-realized (fn [_]
66-
(call-handler ctx))
65+
(d/on-realized (fn [ok?]
66+
;; See
67+
;; https://github.com/clj-commons/aleph/issues/618
68+
;; for why this conditional is necessary
69+
(when ok?
70+
(call-handler ctx)))
6771
;; No need to handle errors here since
6872
;; the SSL handler will terminate the
6973
;; whole pipeline by throwing a

test/aleph/tcp_ssl_test.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,22 @@
6161
:trust-store (into-array X509Certificate [ssl/ca-cert])})})]
6262
(is (nil? @(s/take! c)))
6363
(is (nil? @ssl-session) "SSL session should be undefined")))))
64+
65+
(deftest test-connection-close-during-ssl-handshake
66+
(let [ssl-session (atom nil)
67+
connection-closed (promise)
68+
notify-connection-closed (netty/channel-handler
69+
:channel-inactive
70+
([_ ctx]
71+
(deliver connection-closed true)
72+
(.fireChannelInactive ctx)))]
73+
(with-server (tcp/start-server (ssl-echo-handler ssl-session)
74+
{:port 10001
75+
:ssl-context ssl/server-ssl-context
76+
:pipeline-transform (fn [p]
77+
(.addLast p notify-connection-closed))})
78+
(let [c @(tcp/client {:host "localhost"
79+
:port 10001})]
80+
(s/close! c)
81+
(is (deref connection-closed 1000 false))
82+
(is (nil? @ssl-session) "SSL session should be undefined")))))

0 commit comments

Comments
 (0)