Skip to content

Commit 1f4b6d5

Browse files
committed
Merge remote-tracking branch 'joelittlejohn/avoid-connmgr-shutdown'
2 parents 2bc3a97 + 22bea39 commit 1f4b6d5

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/clj_http/conn_mgr.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
(org.apache.http.conn.scheme PlainSocketFactory
1212
SchemeRegistry Scheme)
1313
(org.apache.http.impl.conn BasicClientConnectionManager
14-
SchemeRegistryFactory)
15-
(org.apache.http.impl.conn PoolingClientConnectionManager)))
14+
PoolingClientConnectionManager
15+
ProxySelectorRoutePlanner
16+
SchemeRegistryFactory
17+
SingleClientConnManager)))
1618

1719
(def ^SSLSocketFactory insecure-socket-factory
1820
(SSLSocketFactory. (reify TrustStrategy
@@ -102,6 +104,10 @@
102104

103105
(def dmcpr ConnPerRouteBean/DEFAULT_MAX_CONNECTIONS_PER_ROUTE)
104106

107+
(defn reusable? [^ClientConnectionManager conn-mgr]
108+
(not (or (instance? SingleClientConnManager conn-mgr)
109+
(instance? BasicClientConnectionManager conn-mgr))))
110+
105111
(defn make-reusable-conn-manager
106112
"Creates a default pooling connection manager with the specified options.
107113

src/clj_http/core.clj

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
(org.apache.http.entity ByteArrayEntity StringEntity)
2525

2626
(org.apache.http.impl.client DefaultHttpClient)
27-
(org.apache.http.impl.conn BasicClientConnectionManager
28-
SingleClientConnManager
29-
ProxySelectorRoutePlanner)
27+
(org.apache.http.impl.conn ProxySelectorRoutePlanner)
3028
(org.apache.http.impl.cookie BrowserCompatSpec)
3129
(org.apache.http.util EntityUtils)))
3230

@@ -134,7 +132,6 @@
134132
(Integer. ^Long v)
135133
true v)))))
136134

137-
138135
(defn- coerce-body-entity
139136
"Coerce the http-entity from an HttpResponse to either a byte-array, or a
140137
stream that closes itself and the connection manager when closed."
@@ -146,9 +143,7 @@
146143
(try
147144
(proxy-super close)
148145
(finally
149-
(when (or (instance? SingleClientConnManager conn-mgr)
150-
(instance? BasicClientConnectionManager conn-mgr))
151-
;;(println "Shutting down connection manager")
146+
(when-not (conn/reusable? conn-mgr)
152147
(.shutdown conn-mgr))))))))
153148

154149
(defn- print-debug!
@@ -254,8 +249,7 @@
254249
(proxy [HttpResponseInterceptor] []
255250
(process [resp ctx]
256251
(response-interceptor resp ctx)))))
257-
(when (or (instance? SingleClientConnManager conn-mgr)
258-
(instance? BasicClientConnectionManager conn-mgr))
252+
(when-not (conn/reusable? conn-mgr)
259253
(.addHeader http-req "Connection" "close"))
260254
(doseq [[header-n header-v] headers]
261255
(if (coll? header-v)
@@ -301,5 +295,6 @@
301295
(dissoc :save-request?))
302296
resp))
303297
(catch Throwable e
304-
(.shutdown ^ClientConnectionManager conn-mgr)
298+
(when-not (conn/reusable? conn-mgr)
299+
(.shutdown ^ClientConnectionManager conn-mgr))
305300
(throw e))))))

0 commit comments

Comments
 (0)