Skip to content

Commit 23feda1

Browse files
committed
client: ensure response in case of Exception
1 parent 985d535 commit 23feda1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/aleph/http/client.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,11 @@
554554
;; might be different in case we use :multipart
555555
(reset! save-body body))
556556

557-
(netty/safe-execute ch
558-
(http/send-message ch true ssl? req' body))))
557+
(-> (netty/safe-execute ch
558+
(http/send-message ch true ssl? req' body))
559+
(d/catch' (fn [e]
560+
(s/put! responses e)
561+
(netty/close ch))))))
559562

560563
;; this will usually happen because of a malformed request
561564
(catch Throwable e

src/aleph/http/core.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@
539539
(try
540540
(send-streaming-body ch msg body)
541541
(catch Throwable e
542-
(log/error e "error sending body of type " class-name)))))]
542+
(log/error e "error sending body of type " class-name)
543+
(throw e)))))]
543544

544545
(when-not keep-alive?
545546
(handle-cleanup ch f))

test/aleph/http_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@
273273
{:body (io/file "test/file.txt")
274274
:pool client-pool}))))))))
275275

276+
(deftest test-invalid-body
277+
(let [client-url (str "http://localhost:" port)]
278+
(with-handler identity
279+
(is (thrown? IllegalArgumentException
280+
@(http-put client-url
281+
{:body 123}))))))
282+
276283
(def characters
277284
(let [charset (conj (mapv char (range 32 127)) \newline)]
278285
(repeatedly #(rand-nth charset))))

0 commit comments

Comments
 (0)