Skip to content

Commit 8412070

Browse files
committed
Wrap Netty's ConnectTimeoutException in our ConnectionTimeoutException
This should make callers' lives a little easier...
1 parent 0577627 commit 8412070

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/aleph/http.clj

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
RequestCancellationException
2424
RequestTimeoutException)
2525
(io.aleph.dirigiste Pools)
26+
(io.netty.channel ConnectTimeoutException)
2627
(io.netty.handler.codec Headers)
2728
(io.netty.handler.codec.http HttpHeaders)
2829
(java.net
@@ -396,10 +397,18 @@
396397
(-> (first conn)
397398
(maybe-timeout! connection-timeout)
398399

399-
;; connection timeout triggered
400-
(d/catch' TimeoutException
401-
(fn [^Throwable e]
402-
(d/error-deferred (ConnectionTimeoutException. e))))
400+
;; connection establishment failed
401+
(d/catch'
402+
(fn [e]
403+
(if (or (instance? TimeoutException e)
404+
;; Unintuitively, this type doesn't inherit from TimeoutException
405+
(instance? ConnectTimeoutException e))
406+
(do
407+
(log/error e "Timed out waiting for connection to be established")
408+
(d/error-deferred (ConnectionTimeoutException. ^Throwable e)))
409+
(do
410+
(log/error e "Connection failure")
411+
(d/error-deferred e)))))
403412

404413
;; actually make the request now
405414
(d/chain'

test/aleph/http_test.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
ChannelHandlerContext
3232
ChannelOutboundHandlerAdapter
3333
ChannelPipeline
34-
ChannelPromise
35-
ConnectTimeoutException)
34+
ChannelPromise)
3635
(io.netty.handler.codec TooLongFrameException)
3736
(io.netty.handler.codec.compression
3837
CompressionOptions
@@ -638,7 +637,7 @@
638637
(deftest test-pool-connect-timeout
639638
(binding [*connection-options* {:connect-timeout 2}]
640639
(with-handler basic-handler
641-
(is (thrown? ConnectTimeoutException
640+
(is (thrown? ConnectionTimeoutException
642641
(deref (http/get "http://192.0.2.0" ;; "TEST-NET" in RFC 5737
643642
(merge (default-request-options) {:pool *pool*
644643
:connection-timeout 500}))

0 commit comments

Comments
 (0)