dakrone / dakrone/clj-http

Async requests errors

Open
#459 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.8k
Forks
410
PR merge metrics
No merged PRs in 30d

Description

I'm trying to run async requests with clj-http:

(comment

  (require '[clj-http.client :as client])
  (require '[clj-http.conn-mgr :as conn])
  (require '[clj-http.core :as http-core])
  (def base "https://example.com")
  (def links (for [i (range 0 10)]
               (str base "/" i)))
  (def resps (atom []))
  (def errors (atom []))
  (time
   (client/with-async-connection-pool {:timeout 5 :threads 4 :insecure? false :default-per-route 10}
     (do
       (reset! resps [])
       (let [;; acm (conn/make-reuseable-async-conn-manager {})
             ;; ahclient (http-core/build-async-http-client {} acm base nil)
             handle-response (fn [res] (swap! resps conj res))
             handle-failure (fn [res] (swap! errors conj res))
             futures (for [l links]
                       (do
                         (debug "Getting" l)
                         (client/get l
                                     {:async? true
                                      ;; :connection-manager acm
                                      ;; :http-client ahclient
                                      }
                                     handle-response handle-failure)))]
         ;; wait for all futures to finish
         (doseq [f futures]
           (.get f))))))
  (count @resps)
  (count @errors)
  
  )

I keep seeing errors like:

Jul 19, 2018 9:00:55 PM org.apache.http.impl.nio.client.InternalHttpAsyncClient run
SEVERE: I/O reactor terminated abnormally
java.lang.IllegalStateException: Illegal state ACTIVE
	at org.apache.http.util.Asserts.check(Asserts.java:46)
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:313)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194)
	at clj_http.conn_mgr.proxy$org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$ReuseableAsyncConnectionManager$fff3515b.execute(Unknown Source)
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
	at java.lang.Thread.run(Thread.java:745)

and

org.apache.http.ConnectionClosedException: Connection closed unexpectedly
  java.util.concurrent.ExecutionException: org.apache.http.ConnectionClosedException: Connection closed unexpectedly

Any pointers?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the async request example using clj-http.client/with-async-connection-pool, then inspect the clj-http.conn-mgr and clj-http.core paths named in the report alongside the Apache HTTP async stack trace. Done should include a confirmed cause for the reactor termination and a defined correction or documented limitation, but the issue does not specify the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.