cch1 / http.async.client

Async Http Client - Clojure
http://cch1.github.com/http.async.client
267 stars 40 forks source link

Empty response body hangs c/body, c/string #26

Closed jkk closed 12 years ago

jkk commented 12 years ago

I notice you had an apparent fix for this in issue #4, but it's still happening for me, although inconsistently. It seems to happen after repeated calls to c/GET that return an empty body.

My hackish workaround was to add this to the :completed callback:

(when-not (realized? (:body resp))
  (deliver (:body resp) nil))

Not sure if this "fix" is reliable or whether onCompleted could be called before the body is done being processed.

neotyk commented 12 years ago

Thanks for reporting this issue.

I'll try to reproduce it. Just to make sure, what version are you at?

jkk commented 12 years ago

I'm using 0.4.0.

neotyk commented 12 years ago

I've tried to reproduce it, unfortunately with little luck. Can you please see test extract-empty-body 1

I also modified for testing this issue by wrapping body of this test in (dotimes [_ 100] ..) No luck reproducing it here as well.

Please tell me how your usage is different from one in test extract-empty-body.

btatnall commented 12 years ago

I was able to reproduce with a server that does not return a body (headers only). The problem with test extract-empty-body is the presence of await. If you remove the await then the test suite will hang indefinitely. Adding the body delivery in onComplete fixes that problem.

diff --git a/test/http/async/client/test.clj b/test/http/async/client/test.clj
index 6dbae1f..ba91a4a 100644
--- a/test/http/async/client/test.clj
+++ b/test/http/async/client/test.clj
@@ -598,7 +598,7 @@

 (deftest extract-empty-body
-  (let [resp (await (GET *client* "http://localhost:8123/empty"))]
+  (let [resp (GET *client* "http://localhost:8123/empty")]
     (is (nil? (string resp)))))

diff --git a/src/clj/http/async/client/request.clj b/src/clj/http/async/client/request.clj
index a034ff0..3640269 100644
--- a/src/clj/http/async/client/request.clj
+++ b/src/clj/http/async/client/request.clj
@@ -255,7 +255,8 @@
             onCompleted [this]
             (do
               (completed resp)
-              (deliver (:done resp) true)))
+              (deliver (:done resp) true)
+              (deliver (:body resp) nil)))
neotyk commented 12 years ago

Updated clojars: https://clojars.org/http.async.client Please test with that last snapshot.

btatnall commented 12 years ago

Would it be possible to have a non-snapshot release for this fix?

neotyk commented 12 years ago

Yes, preparing v0.4.1 release.

neotyk commented 12 years ago

v0.4.1. released. Thank you!