Skip to content

Commit 481966c

Browse files
KingMobarnaudgeiser
authored andcommitted
Close client Netty channel on malformed request
Add some docstrings
1 parent 82d731c commit 481966c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/aleph/http/client.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,15 @@
555555
(reset! save-body body))
556556

557557
(-> (netty/safe-execute ch
558-
(http/send-message ch true ssl? req' body))
558+
(http/send-message ch true ssl? req' body))
559559
(d/catch' (fn [e]
560560
(s/put! responses (d/error-deferred e))
561561
(netty/close ch))))))
562562

563563
;; this will usually happen because of a malformed request
564564
(catch Throwable e
565-
(s/put! responses (d/error-deferred e)))))
565+
(s/put! responses (d/error-deferred e))
566+
(netty/close ch))))
566567
requests)
567568

568569
(s/on-closed responses

src/aleph/http/core.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@
509509
(d/catch' (fn [_]))))]
510510

511511
(defn send-message
512+
"Write an HttpMessage and body to a Netty channel.
513+
514+
Accepts Strings, ByteBuffers, ByteBufs, byte[], ChunkedInputs,
515+
Files, Paths, HttpFiles, seqs and streams for bodies.
516+
517+
Seqs and streams must be, or be coercible to, a stream of ByteBufs."
512518
[ch keep-alive? ssl? ^HttpMessage msg body]
513519

514520
(let [f (cond

src/aleph/netty.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,12 @@
272272
x
273273
(.channel ^ChannelHandlerContext x)))
274274

275-
(defmacro safe-execute [ch & body]
275+
(defmacro safe-execute
276+
"Executes the body on the event-loop (an executor service) associated with the Netty channel.
277+
278+
Executes immediately if current thread is in the event loop. Otherwise, returns a deferred
279+
that will hold the result once done."
280+
[ch & body]
276281
`(let [f# (fn [] ~@body)
277282
event-loop# (-> ~ch aleph.netty/channel .eventLoop)]
278283
(if (.inEventLoop event-loop#)

0 commit comments

Comments
 (0)