Created
November 11, 2016 18:03
-
-
Save OlegTheCat/5805e3202e71e514ff1d0c7993318437 to your computer and use it in GitHub Desktop.
Aleph connection leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns aleph-conn-leak.core | |
(:require [aleph.http :as http] | |
[org.httpkit.server :as hkit] | |
[manifold.deferred :as d] | |
[taoensso.timbre :as log]) | |
(:import (java.net InetAddress InetSocketAddress))) | |
(comment | |
dependencies are as follows | |
[[org.clojure/clojure "1.8.0"] | |
[com.taoensso/timbre "4.7.4"] | |
[aleph "0.4.1"] | |
[http-kit "2.1.16"]]) | |
(defn handler [_] | |
{:status 200 | |
:body "Hello, world"}) | |
(defn start-server [] | |
(hkit/run-server #'handler {:port 9992 | |
:ip "localhost"})) | |
(def server (start-server)) | |
(def client-pool (http/connection-pool {:keep-alive? true | |
:connections-per-host 128})) | |
(defn make-request [] | |
(http/post "http://localhost:9992" {:headers {"Connection" "Close"} ;; this is important | |
:pool client-pool})) | |
(defn make-requests [num-reqs] | |
(let [req-count (atom 0)] | |
(->> (repeatedly num-reqs #(make-request)) | |
(map #(d/chain % (fn [_] | |
(log/infof "---> Request done: %s" | |
(swap! req-count inc)) | |
:ok))) | |
doall | |
(apply d/zip)))) | |
;; fails with ExceptionInfo connection was closed clojure.core/ex-info (core.clj:4617) | |
@(make-requests 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment