Skip to content

Commit b000d98

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

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/aleph/http.clj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ReadTimeoutException
2323
RequestTimeoutException)
2424
(io.aleph.dirigiste Pools)
25+
(io.netty.channel ConnectTimeoutException)
2526
(io.netty.handler.codec Headers)
2627
(io.netty.handler.codec.http HttpHeaders)
2728
(java.net
@@ -384,18 +385,18 @@
384385
(maybe-timeout! connection-timeout)
385386

386387
;; connection timeout triggered, dispose of the connetion
387-
(d/catch' TimeoutException
388-
(fn [^Throwable e]
389-
(log/error e "Timed out waiting for connection to be established")
390-
(flow/dispose pool k conn)
391-
(d/error-deferred (ConnectionTimeoutException. e))))
392-
393-
;; connection failed, bail out
394388
(d/catch'
395389
(fn [e]
396-
(log/error e "Connection failure")
397390
(flow/dispose pool k conn)
398-
(d/error-deferred e)))
391+
(if (or (instance? TimeoutException e)
392+
;; Unintuitively, this type doesn't inherit from TimeoutException
393+
(instance? ConnectTimeoutException e))
394+
(do
395+
(log/error e "Timed out waiting for connection to be established")
396+
(d/error-deferred (ConnectionTimeoutException. ^Throwable e)))
397+
(do
398+
(log/error e "Connection failure")
399+
(d/error-deferred e)))))
399400

400401
;; actually make the request now
401402
(d/chain'

test/aleph/http_test.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
ChannelHandlerContext
3030
ChannelOutboundHandlerAdapter
3131
ChannelPipeline
32-
ChannelPromise
33-
ConnectTimeoutException)
32+
ChannelPromise)
3433
(io.netty.handler.codec TooLongFrameException)
3534
(io.netty.handler.codec.compression
3635
CompressionOptions
@@ -637,7 +636,7 @@
637636
(deftest test-pool-connect-timeout
638637
(binding [*connection-options* {:connect-timeout 2}]
639638
(with-handler basic-handler
640-
(is (thrown? ConnectTimeoutException
639+
(is (thrown? ConnectionTimeoutException
641640
(deref (http/get "http://192.0.2.0" ;; "TEST-NET" in RFC 5737
642641
(merge (default-request-options) {:pool *pool*
643642
:connection-timeout 500}))

0 commit comments

Comments
 (0)